You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

未引入ProfileInstaller却致Android Kotlin应用崩溃,如何移除?

解决ProfileInstaller间接引入导致的AssetManager崩溃问题

我用Kotlin开发的标准Android应用出现以下崩溃,堆栈中无自研代码,且未主动引入ProfileInstaller依赖,经排查它被androidx.lifecycle:lifecycle-runtime、androidx.activity:activity、androidx.navigation:navigation-common等依赖间接引入:

E  java.lang.RuntimeException: AssetManager has been closed
E      at android.content.res.AssetManager.ensureOpenLocked(AssetManager.java:519)
E      at android.content.res.AssetManager.openFd(AssetManager.java:897)
E      at androidx.profileinstaller.DeviceProfileWriter.openStreamFromAssets(DeviceProfileWriter.java:190)
E      at androidx.profileinstaller.DeviceProfileWriter.getProfileInputStream(DeviceProfileWriter.java:210)
E      at androidx.profileinstaller.DeviceProfileWriter.read(DeviceProfileWriter.java:164)
E      at androidx.profileinstaller.ProfileInstaller.transcodeAndWrite(ProfileInstaller.java:444)
E      at androidx.profileinstaller.ProfileInstaller.writeProfile(ProfileInstaller.java:575)
E      at androidx.profileinstaller.ProfileInstaller.writeProfile(ProfileInstaller.java:515)
E      at androidx.profileinstaller.ProfileInstaller.writeProfile(ProfileInstaller.java:479)
E      at androidx.profileinstaller.ProfileInstallerInitializer.lambda$writeInBackground$2(ProfileInstallerInitializer.java:145)
E      at androidx.profileinstaller.ProfileInstallerInitializer$$ExternalSyntheticLambda2.run(Unknown Source:2)
E      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E      at java.lang.Thread.run(Thread.java:923)

移除ProfileInstaller依赖

在模块级build.gradle(或build.gradle.kts)中,通过exclude规则移除所有间接引入的ProfileInstaller:

Groovy DSL 配置

dependencies {
    configurations.all {
        exclude group: 'androidx.profileinstaller', module: 'profileinstaller'
    }

    // 保留你的其他依赖配置
}

Kotlin DSL 配置

dependencies {
    configurations.all {
        exclude(group = "androidx.profileinstaller", module = "profileinstaller")
    }

    // 保留你的其他依赖配置
}

验证移除结果

执行以下Gradle命令检查依赖树,确认profileinstaller已无任何引用:

./gradlew app:dependencies

内容的提问来源于stack exchange,提问作者johngray1965

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 02:05:56