Search code examples
androidandroid-studiosdknoclassdeffounderror

Error NoClassDefFoundError on Android 5 but it's Working on Higher Android Versions like 8, 9, 10


I'm frustrating for a while due to this error, I have an Android app and it's working fine on my phone(android version 8), and my moms(version 10) but not working on my sisters tablet with android version 5. the error happens when the app is going to create a ClientConfig object to sending a sms after entering phone number for registration. it syas:

Method threw 'java.lang.NoClassDefFoundError' exception.

and here is the stack trace:

0 = org.glassfish.jersey.client.ClientConfig$State.<init>(ClientConfig.java:160)
1 = org.glassfish.jersey.client.ClientConfig.<init>(ClientConfig.java:515)
2 = com.xyz.asd.services.UserServices.RegisterNewUser(UserServices.java:48)

also the cause says:

java.lang.NoClassDefFoundError: org.glassfish.jersey.model.internal.CommonConfig

although I can see there is

jersey-common-2.27.jar and I can locate CommonConfig on the package org.glassfish.jersey.model.internal.

and these are some settigs:

   compileSdkVersion 30
    minSdkVersion 14
    targetSdkVersion 30
    multiDexEnabled true

I have cleaned up Android Studio's gradle and all caches, cleaned the project, used some Dex options but nothing happened. before sending read all related wuestions about NoClassDefFoundError on stack overflow with o gain.

I will appreciate any help...


Solution

  • after googling and trying some ways, sugar saved me!

    compileOptions {
            coreLibraryDesugaringEnabled true
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    

    then we need to add :

    dependencies {
        coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9'
        ....
    }
    

    and it's working fine...

    here is some description of sugar: java-8-in-android-apps and this is the resource at develper: Use Java 8 language features and APIs