java.lang.NoClassDefFoundError:无法解决:Landroid/support/v4/content/LocalBroadcastManager 仅在构建 APK 上
Posted
技术标签:
【中文标题】java.lang.NoClassDefFoundError:无法解决:Landroid/support/v4/content/LocalBroadcastManager 仅在构建 APK 上【英文标题】:java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/LocalBroadcastManager only on Build APK 【发布时间】:2018-01-23 14:14:19 【问题描述】:我在这里和谷歌上搜索了很多,但没有找到解决我问题的答案。当我从即时运行运行我的应用程序时,它运行良好。当我生成我的发行版 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
【问题讨论】:
【参考方案1】:我遇到了类似的问题。
这是因为启用了即时运行功能。只需禁用它,清理项目然后构建项目。现在生成发布 Apk。它会起作用的。
可能是Android Studio没有包含Apk中的所有文件,当我们使用即时运行来加快进程时。
在电脑上:
Android Studio --> 文件 --> 设置 --> 构建、执行、部署 --> 即时运行。
在 Mac 上:
Android Studio --> 首选项 --> 构建、执行、部署 --> 即时运行。
【讨论】:
谢谢,按照您的建议解决了我与该主题相关的问题,但现在我遇到了这个问题:Process: br.com.turbi.turbi, PID: 28785 java.lang.NoClassDefFoundError: Failed分辨率:Landroid/support/graphics/drawable/VectorDrawableCompat;即使从 Android Studio 运行。有什么线索吗? @ArthurTavais 打开另一个问题,引用这个问题。 把那个问题的链接发给我,我无法得到那个问题 @ArthurTavais 您需要包含 appcompat-v7 库和可能的设计支持库,这也需要 appcompat 库。【参考方案2】:对我有用的解决方案是添加依赖项
implementation "com.android.support:support-v4:<compileSdkVersion>.x.x"
在我的 gradle 依赖项中。
你可以根据你的compileSdkVersionhere查看版本。
从 sdk 版本 29 开始,您需要将项目转换为 androidx 并使用新的dependency
【讨论】:
【参考方案3】:我在迁移到 AndroidX 后遇到了这个问题。
我添加了以下依赖项。
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
【讨论】:
【参考方案4】:这个问题是因为第三方库仍在使用 v4 支持库。 要解决此问题,请在 gradle.properties
中添加以下内容# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
【讨论】:
以上是关于java.lang.NoClassDefFoundError:无法解决:Landroid/support/v4/content/LocalBroadcastManager 仅在构建 APK 上的主要内容,如果未能解决你的问题,请参考以下文章