As I upgraded agp version from 4.1.0 to 7.4.2 (gradle version 7.5.1), a NoClassDefFoundError exception got and the app crashed.
Since I upgraded agp from 4.1.0 to 7.0, dx has deprecated by default and the block dexOptions have no effect and my configurations are before:
dexOptions {
javaMaxHeapSize "4000M"
jumboMode true
threadCount 6
preDexLibraries false
additionalParameters += "--set-max-idx-number=65000"
additionalParameters += "--minimal-main-dex"
}
agp says that dex operations are optimized by agp by default. So I deleted the block , then build received the same error. google ..., I found a solution is to specify the correct r8 version appropriate to agp, I still received the same error randomly. I upgraded agp to 7.4.2 and gradle to 7.5.1 and deleted r8 version define, the same error still occurs. building ... the error occurs randomly. the dex proguard seems does nothing. Agp native-dex default by api 21 and no proguard supplied.
I suppose that the cause of error is the d8 dex memory as that when I build on CI, the frequency of error occurs reduced. Is there any method to configure the dex or any other way to solve it? or any way to use dx?
By the way, I upgraded kotlin version as the android developers website to 1.8.10.
errors below:
Process: com.***.***, PID: 20480
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/***/***/Logger;
at ......
at ......
......
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
sometimes it becomes:
Process: com.***.***, PID: 20480
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/CoreComponentFactory;
eg:
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;
java.lang.NoClassDefFoundError: Failed resolution of: LandroidX/collection/ArrayMap;
java.lang.NoClassDefFoundError: Failed resolution of: com/{$privatePackage}/AppUpgradeService;
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/startup/AppInitializer;
all above follow by this:
Caused by: java.lang.ClassNotFoundException: Didn't find class "***" on path: DexPathList[[zip file "system/framework/org.apache.http.legacy.boot.jar", zip file ...... /base.apk"], nativeLibraryDirectories=[//***==/lib/x86_64]...]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... business code