在具有Android Studio 2.2RC的Android 5.1上运行应用程序时出现java.lang.NoClassDefFoundError [英] java.lang.NoClassDefFoundError when running app with Android 5.1 with Android Studio 2.2RC

查看:84
本文介绍了在具有Android Studio 2.2RC的Android 5.1上运行应用程序时出现java.lang.NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用装有Android 6.0或Android 7.0的设备时,我的应用程序正在构建并正常运行,但是在运行任何具有Android 5.1(未经过较低测试)的设备时,它会失败,并出现以下异常:

My app is building and running ok when using devices with Android 6.0 or Android 7.0 but when running any device with Android 5.1 (Haven't tested lower) it fails with the following exception:

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文件中包括了所有必需的库(在这种情况下,日志显示了一个Google库,但其他人都发生了).我还确保已启用Multidex,并尝试清理和重建项目以及删除应用程序并重新安装.

I've made sure that i have included all the necessary libraries in my gradle file (In this case, the log shows a google library but it has happened with others). I've also made sure that Multidex is enabled and tried cleaning and rebuilding the project as well as deleting the app and reinstalling.

我已隔离出可能导致崩溃的某些情况:

I've isolated some conditions that may be causing the crash:

  • 即时运行已禁用
  • 为多个设备构建应用程序

我正在使用Android Studio 2.2RC

I'm using Android Studio 2.2RC

稳定版2.2仍在发生

推荐答案

这是我们在runtime/dex_file.cc中看到的内容

Here what we can see in runtime/dex_file.cc

bool DexFile::OpenFromZip(...) {
    ...
    while (i < 100) {
        std::string name = StringPrintf("classes%zu.dex", i)
        ...
    }
    ...
}

因此,如果您有超过100个dex文件,则会收到此NoClassDefFoundError.

So if you have more than 100 dex files you get this NoClassDefFoundError.

跟踪器中存在此行为的问题:

There are issues in the tracker for this behavior:

https://code.google.com/p/android/问题/详细信息?id = 234367 https://code.google.com/p/android/issues/detail ?id = 170485

可以通过禁用预删除来避免此错误.因此,您可以输入

It is possible to avoid this error by disabling pre-dexing. So you can put something like

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根文件中.

in the root build.gradle file.

这篇关于在具有Android Studio 2.2RC的Android 5.1上运行应用程序时出现java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆