java.lang.NoClassDefFoundError: 失败的分辨率: Landroid/support/v4/content/LocalBroadcastManager only on Build APK

2022-09-04 21:05:51

我在这里和谷歌上搜索了很多,没有找到解决我问题的答案。当我从即时运行运行我的应用程序时,它工作得很好。当我生成我的版本APK时,它不会打开并仅在棒棒糖构建(5.0和5.1,在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

在我的Gradle文件中,我已经将minifyEnabled变成了false:

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

以下是依赖项(我添加了android-support-v4.jar作为外部lib,但它也没有解决问题):

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')

}

希望有人能帮助我,已经在这个问题上花了很多时间和精力,找不到解决方案。提前致谢!

编辑:

在Puneet解决方案之后,我在运行应用程序时开始收到以下错误,有什么线索吗?:

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

答案 1

我遇到了类似的问题。

这是因为启用了即时运行功能。只需禁用它,清理项目,然后生成项目。现在生成发布Apk。它会起作用。

可能是Android Studio没有包括Apk中的所有文件,当我们使用即时运行来加快进程时。

在电脑上:

Android Studio --> File --> 设置 --> 构建、执行、部署 --> Instant Run。

在 Mac 上:

Android Studio --> 首选项 -->构建、执行、部署 --> Instant Run。


答案 2

此问题是因为第三方库仍在使用 v4 支持库。要解决此问题,请在 gradle.properties 中添加以下内容

# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

推荐