0

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
  • Please copy the full error text to clipboard and include it into your question. You can edit your question at any time to improve it. `NoClassDefFoundError` always mentions a class name and this class name is important to understand the problem. The stack trace is also often a valuable information. – Robert Apr 23 '23 at 12:23
  • Do you use Proguard for APK minifying? May be the mentioned classes have been removed by Proguard, so my advice would be to check proguard configuration. – Robert Apr 28 '23 at 07:38
  • the error occured when debug mode which minifyEnabled turned off, the release mode I haven't try yet as the debug mode error, the proguard are disabled by agp7 and the agp will notify that remove the android.enableR8=true, so the tool of minify is now R8. – lx94569456 Apr 29 '23 at 08:21

0 Answers0