23

Today i found this error while trying to run my app. I made the following attempts towards solving it. - First i removed multidex support, but i can still see the slices of apk there. -i also attempted rebuilding the entire project, and updated the android support and play services libraries to the latest as recommended by java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArrayMap

Android Studio - NoClassDefFoundError: Failed resolution of Landroid/support/v4/print/PrintHelper

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/os/BuildCompat.

NoClassDefFoundError: android.support.v4.util.ArrayMap

The stacktrace is as follows

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArrayMap;
at com.google.firebase.FirebaseApp.
<clinit>
(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1751)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1726)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5324)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4898)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4838)
at android.app.ActivityThread.access$1500(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1536)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5636)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.util.ArrayMap" on path: DexPathList[[zip file "/data/app/pinnacle.org.rider-1/base.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_dependencies_apk.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_slice_0_apk.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_slice_1_apk.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_slice_2_apk.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_slice_3_apk.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_slice_4_apk.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_slice_5_apk.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_slice_6_apk.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_slice_7_apk.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_slice_8_apk.apk", zip file "/data/app/pinnacle.org.rider-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/pinnacle.org.rider-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.google.firebase.FirebaseApp.
<clinit>
(Unknown Source) 
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source) 
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source) 
at android.content.ContentProvider.attachInfo(ContentProvider.java:1751) 
at android.content.ContentProvider.attachInfo(ContentProvider.java:1726) 
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) 
at android.app.ActivityThread.installProvider(ActivityThread.java:5324) 
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4898) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4838) 
at android.app.ActivityThread.access$1500(ActivityThread.java:178) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1536) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:194) 
at android.app.ActivityThread.main(ActivityThread.java:5636) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 
Suppressed: java.lang.ClassNotFoundException: android.support.v4.util.ArrayMap
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 19 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Here is my gradle file

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'com.google.firebase.firebase-crash'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "pinnacle.org.rider"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
       // multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }

    useLibrary 'org.apache.http.legacy'
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

      /*  debug {
            minifyEnabled true
            shrinkResources true
        }*/
    }

    dataBinding {
        enabled true
    }

    dexOptions {
        jumboMode = true
        // here heap size give 4g i got this thing from https://groups.google.com/forum/#!topic/adt-dev/P_TLBTyFWVY
        javaMaxHeapSize "4g"
     }

    packagingOptions {
        exclude 'META-INF/NOTICE' // will not include NOTICE file
        exclude 'META-INF/LICENSE' // will not include LICENSE file
        exclude 'META-INF/notice'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license'
        exclude 'META-INF/license.txt'
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile project(':trupple-mvp')
    compile project(':pinbuoy')
    compile 'com.squareup:otto:1.3.8'
    compile 'io.card:android-sdk:5.4.2'
    compile 'com.google.guava:guava:19.0'
    compile 'co.paystack.android:paystack:2.1.2'
    testCompile 'org.robolectric:robolectric:3.1.1'
    compile 'com.google.firebase:firebase-messaging:10.2.0'
    compile 'com.google.firebase:firebase-crash:10.2.0'
    compile 'com.squareup.okhttp3:okhttp:3.3.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.3.0'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.1'
    compile 'com.squareup.retrofit2:converter-jackson:2.0.1'
    compile 'com.github.cooltechworks:CreditCardView:v1.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1'
   // compile 'com.android.support:multidex:1.0.1'
    compile 'javax.annotation:javax.annotation-api:1.2'
    compile 'de.hdodenhof:circleimageview:2.0.0'
    compile 'it.michelelacorte.swipeablecard:library:2.3.0'
    compile 'com.github.jorgecastilloprz:fabprogresscircle:1.01@aar'
    compile 'com.github.lawloretienne:discreteslider:0.0.9'
    compile 'com.jaredrummler:material-spinner:1.1.0'
    compile files('libs/libphonenumber-7.7.0.jar')
    compile('io.socket:socket.io-client:0.8.1') {
        exclude group: 'org.json', module: 'json'
    }
    compile 'com.android.support:support-vector-drawable:25.1.1'
    compile 'com.github.dmytrodanylyk.circular-progress-button:library:1.1.3'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
    testCompile 'org.mockito:mockito-core:1.9.5'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

My custom libraries have the following as their gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    useLibrary 'org.apache.http.legacy'

    dataBinding {
        enabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.google.android.gms:play-services:10.2.0'
    //compile 'com.android.support:support-v4:25.1.1'
    compile 'com.android.support:recyclerview-v7:25.1.1'
    //compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:cardview-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'
    compile 'com.squareup.picasso:picasso:2.5.0'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.1.6'
    compile 'com.google.code.gson:gson:2.7'
    testCompile 'junit:junit:4.12'

}

and the second with

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    testCompile 'junit:junit:4.12'
}

Please i am stuck with this

I solved this by doing the following.

  1. Picking the exact package needed in the play services library module.
  2. Ensure no duplicate of the support library.
  3. Clean and rebuild the project.
  4. Kept the library source under 64k methods, so need for multidex.
MohanKumar
  • 960
  • 10
  • 26
geniusgeek
  • 331
  • 1
  • 2
  • 8

5 Answers5

36

I faced the same problem with Flutter and this question was the first link on Google when I searched my error:

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArraySet

So the root of your problem might be same: AndroidX adaptation. Adding those lines to gradle.properties fixed my problem:

android.useAndroidX=true
android.enableJetifier=true

You may also want to add compileSdkVersion 28 to your app-level build.gradle file. For further information

buraky
  • 937
  • 1
  • 11
  • 18
  • For anyone wondering. When `enableJetifier` flag is set to true, the Android plugin automatically migrates existing third-party libraries to use AndroidX dependencies by rewriting their binaries. The flag is false by default if it is not specified. – Michał Stochmal May 04 '23 at 21:22
2

I had the same problem and solved it by editing the build.gradle file like this:

...

dependencies {
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

  //Add these lines to fix the error.
  implementation 'com.google.firebase:firebase-analytics:17.2.1'
  implementation 'com.google.firebase:firebase-auth:19.2.0'
  implementation 'com.google.firebase:firebase-firestore:21.3.0'
}

apply plugin: 'com.google.gms.google-services'
2
android.useAndroidX=true
android.enableJetifier=true

It worked for me, after adding on gradle.properties

abir-cse
  • 507
  • 3
  • 12
1

It looks you are missing v4 support library in your app gradle dependencies. Try by adding v4 support library

compile 'com.android.support:support-v4:25.1.1'
MSC
  • 422
  • 5
  • 14
  • okey... can you move google-play-services library dependency in your app gradle. – MSC Feb 22 '17 at 04:53
  • I notice that the app works on other devices but not on my phone. my phone runs on android 5.1, API 22, what do you think is the issue? – geniusgeek Feb 23 '17 at 09:38
  • It appears to be an issue with the support-v4:25.X.X library. It is likely that they broke it down into piecemeal archives with the option to include an `-all` or similar collection. I have not resolved the issue, but experienced it myself with LruCache and some other various components. – Abandoned Cart Oct 21 '18 at 18:59
0

for me I found this change fixed my issue. I had a repo that built find in July this year. Then as I kept my build environment up to date with flutter etc, it wouldn't build this project but built my other project fine. I found this difference:

--- a/android/build.gradle
+++ b/android/build.gradle
@@ -5,8 +5,8 @@ buildscript {
     }

     dependencies {
-        classpath 'com.android.tools.build:gradle:3.2.1'
-        classpath 'com.google.gms:google-services:4.2.0'
+        classpath 'com.android.tools.build:gradle:3.3.0'
+        classpath 'com.google.gms:google-services:4.3.0'
     }
 }
Eradicatore
  • 1,501
  • 2
  • 20
  • 38