手机直接debug本身没有问题,但是打包的时候会出现Unable to execute dex: method ID not in[0, 0xffff]: 65536)这种问题导致打包失败,这是单个dex文件方法数超过64k导致的,基本上引入过多的依赖都会出现这个问题,解决方法:
1.导入依赖
'com.android.support:multidex:1.0.1'
2.defaultConfig增加这个设置
multiDexEnabled true
3.android下面增加这个设置
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
以上都是在app的buildl.gradle中设置的,编译。
4.打开自定义的Application,继承MultiDexApplication,并重写attachBaseContext方法
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}