NoClassDefFoundError below SDK 21

后端 未结 3 1129
我寻月下人不归
我寻月下人不归 2020-11-30 02:47

I just experienced an awkward bug in my App.

On my Nexus 5/7, running android 5.0.1/5.0.2, everything works just fine. However if i try running the exact same code o

相关标签:
3条回答
  • 2020-11-30 02:59

    There are three ways how this is going to work.

    1. As @FireZenk noted you can declare this class as the application in your AndroidManifest.xml.
    <application android:name="android.support.multidex.MultiDexApplication">
    

    And actually with the android grade plugin version 0.14.0 and build tools version 21.1.0 when you specify the multiDexEnabled true in the defaultConfig, ProductFlavor, or BuildTypethen it automatically includes dependence to the com.android.support:multidex:1.0.0. You can check that with the androidDependencie task or you run ./gradlew -q android:dependencies command (android: is my android module). So there is no need to explicitly add the

    compile 'com.android.support:multidex:1.0.0'
    

    If you have extended Application class in your app:

    1. Define that your Application extends MultiDexApplication class, like:
    public class MyApplication extends MultiDexApplication {
        ...
    }
    

    or like @user2700475 posted

    1. Have your Application override attachBaseContext:
    public class MyApplication extends Application {
        @Override
        protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);}
    }
    

    With the help of previous answers I manage to find the solution to this problem. I just want to put all this together.

    0 讨论(0)
  • 2020-11-30 03:16

    If you don't have/use Application class, you can put this:

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

    Into your tag on AndroidManifest.xml

    If you already have implemented an Application class, @user2700475 + @sirvon responses are your best choice.

    Also obviously, you need to add the Gradle dependency:

    compile 'com.android.support:multidex:1.0.0'
    

    More info about 65k methods problem: https://developer.android.com/tools/building/multidex.html

    0 讨论(0)
  • 2020-11-30 03:19

    I resolved the issue by adding this to my Application Class.

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    

    Seems to be neccessary for android versions prior 5.

    0 讨论(0)
提交回复
热议问题