我的应用程序在使用
Android 6.0或
Android 7.0的设备时正在构建并运行正常,但在运行任何带有Android 5.1的设备(未测试较低)时,它会失败并出现以下异常:
09-06 11:50:46.100 29601-29601/? E/AndroidRuntime: FATAL EXCEPTION: main Process: me.myapp.main,PID: 29601 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzab; at com.google.firebase.provider.FirebaseInitProvider.zza(Unknown Source) at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) at android.app.ActivityThread.installProvider(ActivityThread.java:5084) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4679) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4619) at android.app.ActivityThread.access$1500(ActivityThread.java:155) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5343) 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:905) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzab" on path: DexPathList[[zip file "/data/app/me.myapp.main-1/base.apk"],nativeLibraryDirectories=[/data/app/me.myapp.main-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.provider.FirebaseInitProvider.zza(Unknown Source) at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) at android.app.ActivityThread.installProvider(ActivityThread.java:5084) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4679) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4619) at android.app.ActivityThread.access$1500(ActivityThread.java:155) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5343) 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:905) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.common.internal.zzab 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) ... 15 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
我已经确保我已将所有必需的库包含在我的gradle文件中(在这种情况下,日志显示了一个谷歌库,但它已经发生在其他人身上).我还确保启用Multidex并尝试清理和重建项目以及删除应用程序并重新安装.
我已经隔离了一些可能导致崩溃的情况:
>即时运行已禁用
>为多个设备构建应用程序
我正在使用Android Studio 2.2RC
编辑:仍然发生稳定的2.2
解决方法
这是我们在runtime / dex_file.cc中可以看到的内容
bool DexFile::OpenFromZip(...) { ... while (i < 100) { std::string name = StringPrintf("classes%zu.dex",i) ... } ... }
因此,如果你有超过100个dex文件,你会得到这个NoClassDefFoundError.
跟踪器中存在此行为的问题:
https://code.google.com/p/android/issues/detail?id=234367
https://code.google.com/p/android/issues/detail?id=170485
通过禁用预解除可以避免此错误.所以你可以把类似的东西
subprojects { project.plugins.whenPluginAdded { plugin -> if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) { project.android.dexOptions.preDexLibraries = false } else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { project.android.dexOptions.preDexLibraries = false } } }
在根build.gradle文件中.