java.lang.NoClassDefFoundError:解析失败:Landroid / support / v4 / content / LocalBroadcastManager仅限构建APK

时间:2017-08-15 15:51:02

标签: java android

我在Google和Google上搜索了很多,但没有找到解决问题的答案。当我从即时运行中运行我的应用程序时,它完美地运行。当我生成我的发布APK时,它不会打开并仅在Lollipop版本上显示此错误(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添加为外部库,但它也没有解决问题):

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

4 个答案:

答案 0 :(得分:3)

我遇到了类似的问题。

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

当我们使用即时运行来固定流程时,Android Studio可能不包括Apk中的所有文件。

在PC上:

  

Android Studio - &gt;档案 - &gt;设置 - &gt;构建,执行,部署 - &gt;   即时运行。

在Mac上:

  

Android Studio - &gt;偏好 - &gt;构建,执行,部署 - &gt;   即时跑步。

答案 1 :(得分:1)

对我有用的解决方案是添加依赖项

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

在我的gradle依赖项中。

您可以根据自己的compileSdkVersion here检查版本。

从sdk 29版开始,您需要将项目转换为androidx并使用新的dependency

答案 2 :(得分:1)

我迁移到 AndroidX 后遇到了这个问题。

我添加了以下依赖项。

implementation 'androidx.legacy:legacy-support-v4:1.0.0'

答案 3 :(得分:0)

这个问题是因为第三方库仍在使用 v4 支持库。 要解决此问题,请在您的 gradle.properties

中添加以下内容
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true