问题原因
Android APK文件本质上是一个压缩文件,它包含的classes.dex文件是Dalvik字节码文件,这个dex文件中存放的就是编译后的Java代码。Dalvik可执行文件规范限制了单个.dex文件最多引用的方法数是65536个。
因此 google为了规避上述问题,推出了MultiDex解决方案解决方法数超限问题
配置方案
- app/build.gradle
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"//必须使用21或之后的版本
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
- Application 类中:
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
//
MultiDex.install(this);
}
8536

被折叠的 条评论
为什么被折叠?



