移动知识

android MultiDex分包

2018-07-03  本文已影响20人  CQ_TYL
相信你肯定在项目中遇到过下面的问题👇
如何解决

如果你的minSdkVersion设置成21及更高,你只需要在build.gradle设置multiDexEnabled为true就可以了:

android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 25
multiDexEnabled true 
}
...
}

如果你的minSdkVersion设置成20及以下,除了上述步骤外你还需要添加依赖库并进行相关配置:

android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true 
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}

在MyApplication中加入下面的代码进行配置:

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

猜你喜欢

热点阅读