问题
因此,我在应用程序模块中集成了JetpackCompose依赖项。但每当启动/启动应用程序时,都会出现以下异常。它在Application
类中失败了。
堆栈跟踪:
2021-10-22 11:16:01.079 16281-16281/com.example E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example, PID: 16281
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_8ff85ea/Offline;
at com.example.app.MyApplication.attachBaseContext(MyApplication.java:719)
at android.app.Application.attach(Application.java:361)
at android.app.Instrumentation.newApplication(Instrumentation.java:1159)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1324)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7223)
at android.app.ActivityThread.access$1600(ActivityThread.java:298)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2172)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:8248)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_8ff85ea.Offline" on path: DexPathList[[zip file "/data/app/~~MsNoI2GIvO6hDqGPC9BKfw==/com.example-jknI-wJelwi0a-NSFCz0ig==/base.apk"]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.example.app.MyApplication.attachBaseContext(MyApplication.java:719)
at android.app.Application.attach(Application.java:361)
at android.app.Instrumentation.newApplication(Instrumentation.java:1159)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1324)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7223)
at android.app.ActivityThread.access$1600(ActivityThread.java:298)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2172)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:8248)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Suppressed: java.io.IOException: No original dex files found for dex location (arm64) /data/app/~~MsNoI2GIvO6hDqGPC9BKfw==/com.example-jknI-wJelwi0a-NSFCz0ig==/split_config.arm64_v8a.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:379)
at dalvik.system.DexFile.<init>(DexFile.java:112)
at dalvik.system.DexFile.<init>(DexFile.java:85)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:439)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:398)
at dalvik.system.DexPathList.<init>(DexPathList.java:166)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:129)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:104)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:981)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:1038)
at android.app.LoadedApk.getResources(LoadedApk.java:1270)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2750)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2742)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7128)
2021-10-22 11:16:01.080 16281-16281/com.example E/AndroidRuntime: ... 8 more
Suppressed: java.io.IOException: No original dex files found for dex location (arm64) /data/app/~~MsNoI2GIvO6hDqGPC9BKfw==/com.example-jknI-wJelwi0a-NSFCz0ig==/split_config.xxhdpi.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:379)
at dalvik.system.DexFile.<init>(DexFile.java:112)
at dalvik.system.DexFile.<init>(DexFile.java:85)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:439)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:398)
at dalvik.system.DexPathList.<init>(DexPathList.java:166)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:129)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:104)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:981)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:1038)
at android.app.LoadedApk.getResources(LoadedApk.java:1270)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2750)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2742)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7128)
... 8 more
我的设置
- IDE:AndroidStudio Arctic Fox-稳定|补丁3
- Java JDK 11
- Kotlin 1.5.30
- Jetpack Compose 1.0.3
- Android Gradle插件7.0.2
- 渐变包装器版本7.0.2
- JaCoCo版本0.8.7
build.gradle:
jacoco {
toolVersion = "0.8.7"
}
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
buildTypes {
debug {
testCoverageEnabled true
}
}
这个问题的解决方案非常有趣。
我们的项目有也使用JaCoCo的远程子模块,在主项目中,我们升级了Android Gradle插件版本,而没有升级远程子模块中的AGP,然后出现了这个问题。这是因为这些子模块也使用了JaCoCo插件。
一旦我们升级了所有使用JaCoCo插件的子模块,并更新了主应用程序中的各个版本,这个问题就得到了解决。
早些时候我们使用AGP 4.2.2,这个问题是在AGP升级到7.x.x.之后出现的