如果我們的Android項(xiàng)目足夠大,又或者引用了較多的第三庫,那么在我們打release包時(shí)一定會(huì)遇到DexIndexOverflowException的報(bào)錯(cuò)異常:
Error:Execution failed for task ':app:transformDexWithDexForProdRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: Cannot merge new index 66561 into a non-jumbo instruction!
在一個(gè)項(xiàng)目中方法的總數(shù)不能超過64K。
解決方法:
如果是類似我上面那樣報(bào)Cannot merge new index 66561 into a non-jumbo instruction,只需要在當(dāng)前app的build.gradle的android{}中添加下面代碼即可:
dexOptions {
jumboMode = true
}