java.lang.NoClassDefFoundError when running app with Android 5.1 with Android Studio 2.2RC

六月ゝ 毕业季﹏ 提交于 2019-12-01 04:48:59

Here what we can see in runtime/dex_file.cc

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

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/issues/detail?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
        }
    }
}

in the root build.gradle file.

alexbirkett

Android 5.1 has an arbitrary limit of 100 dex files

One possible workaround is to disable preDexLibraries which reduces the number of classes.dex files included in an apk.

Add

android {
    dexOptions {
        preDexLibraries false
    }
}

to the app's build.gradle file

Make sure you're using the updated versions of google.android.gms

Invalidate Caches and then Make changes in your app : gradle file :

implementation 'com.android.support.constraint:constraint-layout:1.1.2'
//noinspection GradleCompatible
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:23.4.0'
implementation 'com.android.support:design:23.4.0'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.parse.bolts:bolts-tasks:1.4.0'
implementation 'com.parse:parse-android:1.13.0'
implementation 'com.android.support:multidex:1.0.3'

This worked for me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!