85

For some unknown reason my app suddenly won't build from Android Studio.

I'm keep getting

> 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!

While the same application is built successfully from command line. I've checked method references count and it's way below the dreaded 64k.

I'm using AS 0.8.11 now.

Community
  • 1
  • 1
Martynas Jurkus
  • 9,231
  • 13
  • 59
  • 101

5 Answers5

245

Set the jumboMode property in build.gradle:

android {
    ...
    dexOptions {
        jumboMode true
    }

}

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

Community
  • 1
  • 1
lydia_schiff
  • 2,640
  • 2
  • 10
  • 16
57

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

Kaushik
  • 6,150
  • 5
  • 39
  • 54
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
  • 11
    Adding to `project.properties` did not work so I updated my gradle build script as described here: http://stackoverflow.com/questions/17320088/android-build-dex-jumbo-mode-in-gradle – Martynas Jurkus Sep 29 '14 at 06:42
  • 1
    I did both solutions: adding dex.force.jumbo property and dexOptions but I'm still receiving the same error. Another option? – Juan Saravia Jan 30 '15 at 13:20
  • @juancho,Check : https://developer.android.com/google/play-services/setup.html#split – Haresh Chhelana Jan 30 '15 at 13:26
  • Thanks @HareshChhelana. For some reason it started to work.. but I really didn't do anything special. I have some coworkers who are compiling the project without this options, but now it's working for me. Thanks! – Juan Saravia Jan 30 '15 at 19:25
  • 1
    instead of compiling the entire Google Play Services, i found using the 'base' bundle to be useful, to stay below the 65K dex limit: `compile 'com.google.android.gms:play-services-base:7.3.0'` – kip2 Jul 24 '15 at 10:32
  • The "compile" configuration is now deprecated and should be replaced by "implementation" or "api" – A.A Nov 22 '18 at 12:40
54

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.

onexf
  • 3,674
  • 3
  • 22
  • 36
Sayooj
  • 587
  • 4
  • 6
  • It's work for me. Thanks!!! but what is 'jumboMode' ? Can you please explain me? @Sayooj – D G Sep 20 '18 at 05:21
13

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.

williamj949
  • 11,166
  • 8
  • 37
  • 51
-1

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

SamuraiSong
  • 231
  • 1
  • 2
  • 6