DexException: 无法将新索引65536合并到非巨型指令中

出于某种未知的原因,我的应用程序突然不能从 Android Studio 构建了。

我一直在

> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/martynas/android-sdk/build-tools/19.1.0/dx --dex --num-threads=4 --output
...
...
...
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Cannot merge new index 65536 into a non-jumbo instruction!

同时从命令行成功构建了相同的应用程序。 我已经检查了方法引用计数,它远远低于可怕的64k。

我现在使用 AS0.8.11。

56951 次浏览

Try to add this line on your project.properties

dex.force.jumbo=true

Which increment the limit for strings in a dex files. And your project will probably compile.

Note : Also with jumbo set, the is another limit of 64K only for methods in an single dex. If you get this limit in the future , you will need to remove some dependencies.

Update - Google Play Services 6.5 (12-08-14)

With version 6.5 Google finally unbundled the Google Play Services. So from now on it'll be possible to selectively compile the APIs into your executable.

Example :

compile 'com.google.android.gms:play-services-maps:6.5.+'
compile 'com.google.android.gms:play-services-ads:6.5.+'

For all the other individual Google Play Services APIs check this page on d.android.com.

Update (21-04-2015) : https://developer.android.com/tools/building/multidex.html

This is a bug in the merger when the dex files that are being merged have more than 65536 strings. The new index can't fit in a const-string instruction, and the dex merger doesn't support changing instructions if they are different sizes, so it can't be widened to a const-string/jumbo instruction.This was fixed in jb-mr1 by adding a new option: --force-jumbo.This bug can be fixed by adding "dex.force.jumbo=true" to the project.properties.

Set the jumboMode property in build.gradle:

android {
...
dexOptions {
jumboMode true
}


}

I also found this useful: Showing dex method count by package.

With latest Android Studio and flag "force jumbo" checked on Android Studio compiler settings, this problem disappear.

This works for me. I was getting com.android.dex.DexIndexOverflowException: Cannot merge new index 66636 into a non-jumbo instruction!

android {
...
dexOptions {
jumboMode true
}
}

If this isn't working, you might have reached method reference limit in dex which is a different issue. You need to use either multidex or proGuard.