解决Error:Android Dex: com.android.dex.DexIndexOverflowException: Cannot merge new index 65918 into a

时间:2021-02-04 23:26:19

错误:Error:Android Dex: com.android.dex.DexIndexOverflowException: Cannot merge new index 65918 into a non-jumbo instruction!

例如以下图:

解决Error:Android Dex: com.android.dex.DexIndexOverflowException: Cannot merge new index 65918 into a

直接原因是Java代码太多,jar包太多。

谷歌官方文档已经有解决方式:http://developer.android.com/intl/zh-cn/tools/building/multidex.html

点击打开链接

eclipse的解决方式:在项目中的这个文件project.properties中加入一句话:dex.force.jumbo=true,如图:

解决Error:Android Dex: com.android.dex.DexIndexOverflowException: Cannot merge new index 65918 into a

Android studio 解决方式,须要几个步骤:

第一步,加入 multiDexEnabled = true,如图:

解决Error:Android Dex: com.android.dex.DexIndexOverflowException: Cannot merge new index 65918 into a

第二步。加入依赖于你的build.gradle支持MultiDex库。如图:

解决Error:Android Dex: com.android.dex.DexIndexOverflowException: Cannot merge new index 65918 into a

第三步分3个情况,

假设你没有创建自己的Application 类,在你的清单文件AndroidManifest.xml中配置android.support.multidex.MultiDexApplication就能够了。





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





假设你有自己的Application类了。让它继承 android.support.multidex.MultiDexApplication而不是android.app.Application

假设你的Application继承了其它的类,而且你不想改变或者没办法改变。依照以下的方法重写attachBaseContext()。



@Override

protected void attachBaseContext(Context base) {

    super.attachBaseContext(base);

    MultiDex.install(this);

}

假设没有第二和第三步。可能有些手机执行时会报错,如图:

解决Error:Android Dex: com.android.dex.DexIndexOverflowException: Cannot merge new index 65918 into a

好了,又一次编译。能够通过了,又能够愉快的玩耍了……