Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/LocalBroadcastManager only on Build APK

Tags:

java

android

I have searched a lot here and on Google and found no answer that solved my problem. When i run my app from instant run, it works perfectly. When i generate my release APK, it doesn't open and show this error only on Lollipop builds (5.0 and 5.1, works fine on 6.0>):

08-15 11:31:47.689 2605-2605/br.com.turbi.turbi E/AndroidRuntime: FATAL EXCEPTION: main
  Process: br.com.turbi.turbi, PID: 2605
  java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/LocalBroadcastManager;
      at com.facebook.internal.BoltsMeasurementEventListener.open(BoltsMeasurementEventListener.java:54)
      at com.facebook.internal.BoltsMeasurementEventListener.getInstance(BoltsMeasurementEventListener.java:70)
      at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:289)
      at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:231)
      at com.facebook.internal.FacebookInitProvider.onCreate(FacebookInitProvider.java:20)
      at android.content.ContentProvider.attachInfo(ContentProvider.java:1696)
      at android.content.ContentProvider.attachInfo(ContentProvider.java:1671)
      at android.app.ActivityThread.installProvider(ActivityThread.java:4999)
      at android.app.ActivityThread.installContentProviders(ActivityThread.java:4594)
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4534)
      at android.app.ActivityThread.access$1500(ActivityThread.java:151)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:135)
      at android.app.ActivityThread.main(ActivityThread.java:5254)
      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:903)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
   Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.LocalBroadcastManager" on path: DexPathList[[zip file "/data/app/br.com.turbi.turbi-1/base.apk"],nativeLibraryDirectories=[/data/app/br.com.turbi.turbi-1/lib/x86, /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.facebook.internal.BoltsMeasurementEventListener.open(BoltsMeasurementEventListener.java:54) 
      at com.facebook.internal.BoltsMeasurementEventListener.getInstance(BoltsMeasurementEventListener.java:70) 
      at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:289) 
      at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:231) 
      at com.facebook.internal.FacebookInitProvider.onCreate(FacebookInitProvider.java:20) 
      at android.content.ContentProvider.attachInfo(ContentProvider.java:1696) 
      at android.content.ContentProvider.attachInfo(ContentProvider.java:1671) 
      at android.app.ActivityThread.installProvider(ActivityThread.java:4999) 
      at android.app.ActivityThread.installContentProviders(ActivityThread.java:4594) 
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4534) 
      at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:135) 
      at android.app.ActivityThread.main(ActivityThread.java:5254) 
      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:903) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
    Suppressed: java.lang.ClassNotFoundException: android.support.v4.content.LocalBroadcastManager
      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)
            ... 20 more
   Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

In my Gradle file, i have turned minifyEnabled to false already :

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

And here are the dependencies(i added the android-support-v4.jar as a external lib, but it did not solve the problem either):

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 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:animated-vector-drawable:25.3.1'
compile 'com.android.support:customtabs:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v13:25.3.1'
compile 'com.jakewharton:butterknife:8.5.1'
compile 'com.squareup.okhttp3:okhttp:3.6.0'
compile 'com.kyanogen.signatureview:signature-view:1.0'
compile 'io.card:android-sdk:5.5.0'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.facebook.android:facebook-android-sdk:4.25.0'
compile 'com.google.android.gms:play-services:11.0.1'
compile 'com.google.android.gms:play-services-location:11.0.1'
compile 'com.google.android.gms:play-services-maps:11.0.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-storage:11.0.1'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.vicmikhailau:MaskedEditText:2.0.2'
compile 'com.google.firebase:firebase-crash:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.6'
compile('com.digits.sdk.android:digits:2.0.6@aar') {
    transitive = true;
}
compile 'com.airbnb.android:lottie:2.0.0-beta4'
compile 'com.felipecsl:gifimageview:2.1.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.koushikdutta.ion:ion:2.+'
/** * Glide  ***/
compile 'com.github.bumptech.glide:glide:4.0.0-RC1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC1'
compile 'com.android.support:multidex:1.0.1'
compile files('libs/android-support-v4.jar')

}

Hope someone can help me, already spent a lot of time and effort on this problem and cant find a solution. Thanks on advance!

Edit:

After Puneet solution, i started getting the below error when running the app, any clues? :

FATAL EXCEPTION: main
                                                                Process: br.com.turbi.turbi, PID: 28785
                                                                java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/graphics/drawable/VectorDrawableCompat;
                                                                    at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:734)
                                                                    at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:367)
                                                                    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
                                                                    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
                                                                    at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:711)
                                                                    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
                                                                    at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
                                                                    at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:131)
                                                                    at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:155)
                                                                    at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31)
                                                                    at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55)
                                                                    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
                                                                    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
                                                                    at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
                                                                    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
                                                                    at br.com.turbi.turbi.SplashActivity.onCreate(SplashActivity.java:26)
                                                                    at android.app.Activity.performCreate(Activity.java:5990)
                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
                                                                    at android.app.ActivityThread.access$900(ActivityThread.java:154)
                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                    at android.os.Looper.loop(Looper.java:135)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5294)
                                                                    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:904)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
                                                                 Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.graphics.drawable.VectorDrawableCompat" on path: DexPathList[[zip file "/data/app/br.com.turbi.turbi-2/base.apk"],nativeLibraryDirectories=[/data/app/br.com.turbi.turbi-2/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 android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:734) 
                                                                    at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:367) 
                                                                    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197) 
                                                                    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190) 
                                                                    at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:711) 
                                                                    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195) 
                                                                    at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81) 
                                                                    at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:131) 
                                                                    at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:155) 
                                                                    at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31) 
                                                                    at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55) 
                                                                    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205) 
                                                                    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185) 
                                                                    at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519) 
                                                                    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71) 
                                                                    at br.com.turbi.turbi.SplashActivity.onCreate(SplashActivity.java:26) 
                                                                    at android.app.Activity.performCreate(Activity.java:5990) 
                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311) 
                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420) 
                                                                    at android.app.ActivityThread.access$900(ActivityThread.java:154) 
                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
                                                                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                    at android.os.Looper.loop(Looper.java:135) 
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5294) 
                                                                    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:904) 
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 
                                                                    Suppressed: java.lang.ClassNotFoundException: android.support.graphics.drawable.VectorDrawableCompat
                                                                    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)
                                                                            ... 30 more
                                                                 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
like image 703
Arthur Tavais Avatar asked Aug 15 '17 15:08

Arthur Tavais


3 Answers

This issue is because third party lib is still using v4 support lib. To fix this issue add the following in your gradle.properties

# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
like image 137
PSK Avatar answered Nov 10 '22 12:11

PSK


I faced similar problem.

This is because of the instant run feature is enabled. Just disable it, clean the project then build the project. Now generate release Apk. It will work.

May be Android Studio is not including all files in Apk, when we use the instant run to fasten the process.

On PC:

Android Studio --> File --> Setting --> Build, execution, deploy --> Instant run.

On Mac:

Android Studio --> Preferences --> Build, Execution, Deployment --> Instant Run.

like image 5
Puneet Verma Avatar answered Nov 10 '22 10:11

Puneet Verma


The solution that worked for me was to add the dependency

implementation "com.android.support:support-v4:<compileSdkVersion>.x.x"

in my gradle dependencies.

You can check the version according to your compileSdkVersion here.

From sdk version 29, you need to convert your project to androidx and use the new dependency

like image 2
patchimou Avatar answered Nov 10 '22 11:11

patchimou