NoClassDefFoundError with Android Studio on Android 4

杀马特。学长 韩版系。学妹 提交于 2019-11-26 12:23:26
karl

I was incompletely implementing MultiDex support, so some of my classes weren't in the proper dex file. To fix it, you have to do more than just set multiDexEnabled = true in your defaultConfig block. You also have to:

  1. Include compile 'com.android.support:multidex:1.0.1' in your dependencies
  2. Have your Application class extend MultiDexApplication instead of just Application. Alternatively, you can call MultiDex.install() in attachBaseContext() of your application.

See https://developer.android.com/tools/building/multidex.html for more details.

Mahendra Tejaswi

1) Add multiDexEnabled = true in your default Config

2) Add compile com.android.support:multidex:1.0.0 in your dependencies

3) Application class extend MultiDexApplication instead of just Application

HarshitG

I solved the problem by removing multiDexEnabled = true in my case.

1) add multiDexEnabled = true in your defaultConfig in build.gradle.

2) You also have to Include compile 'com.android.support:multidex:1.0.1'

3) add the following to your "application" tag in your manifest:

android:name="android.support.multidex.MultiDexApplication"

its working with me , hope that help

arshad abbas

I also issue get resolved after doing following steps

1) add multiDexEnabled = true in your defaultConfig in build.gradle.

2) You also have to Include compile com.android.support:multidex:1.0.1

3) add the following to your "application" tag in your manifest:

android:name="android.support.multidex.MultiDexApplication"

I got the same issue, tried all solutions suggested on StackOverflow but they did not work in my case.
After that I found out that one of libraries compiled by Java 8. So, I need to enable Java 8 in my project too.

  android {
    //...
    compileOptions {
      sourceCompatibility JavaVersion.VERSION_1_8
      targetCompatibility JavaVersion.VERSION_1_8
    }
  }

There are many reasons which leads to this error. Hope it helps.

In my case, it was Kotlin forEach was causing the exception. More info here: java.lang.NoClassDefFoundError $$inlined$forEach$lambda$1 in Kotlin

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