-4

Any ideas on what went wrong? I am using Libgdx

> Error:Execution failed for task ':android:dexDebug'. com.android.ide.common.internal.LoggedErrorException: Failed to run command:     C:\Users\Steven\AppData\Local\Android\sdk\build-tools\build-tools-20.0.0\dx.bat
--dex --no-optimize --output

Error Code: 2 Output:

UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536
        at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:501)
        at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:276)
        at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:490)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:167)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
        at com.android.dx.command.dexer.Main.run(Main.java:230)
        at com.android.dx.command.dexer.Main.main(Main.java:199)
        at com.android.dx.command.Main.main(Main.java:103)
>
Psypher
  • 10,717
  • 12
  • 59
  • 83
user3396986
  • 23
  • 1
  • 6
  • Looks like some command failed to run. This is the command which failed: `C:\Users\Steven\AppData\Local\Android\sdk\build-tools\build-tools-20.0.0\dx.bat --dex --no-optimize --output` – CubeJockey Jun 29 '15 at 20:08
  • does this help? http://stackoverflow.com/questions/21102598/android-studio-unexpected-top-level-exception – Olivier Poulin Jun 29 '15 at 20:08

1 Answers1

0

You are running into the famous multi-dexing problem where a single Dex file cannot declare more than 65536 methods. This has already been solved in recent versions of the Android build tools and all you have to do is to make your application reference MultiDexApplication and add:

android {
  defaultConfig {
    ...
    multiDexEnabled = true
  }
}

to your build script. There are more details about this problem in the official documentation. See Building Apps with Over 65K Methods.

Mike Laren
  • 8,028
  • 17
  • 51
  • 70