简体   繁体   中英

Cannot run project in Android Studio

When I was trying to run my project in Android Studio, I got the following error message

Execution failed for task ':CricHQ:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/19.0.1/dx -JXmx4g --dex --output 
Error Code:
2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Cannot merge new index 66514 into a non-jumbo instruction!
    at com.android.dx.merge.InstructionTransformer.jumboCheck(InstructionTransformer.java:108)
    at com.android.dx.merge.InstructionTransformer.access$800(InstructionTransformer.java:25)
    at com.android.dx.merge.InstructionTransformer$StringVisitor.visit(InstructionTransformer.java:71)
    at com.android.dx.io.CodeReader.callVisit(CodeReader.java:114)
    at com.android.dx.io.CodeReader.visitAll(CodeReader.java:89)
    at com.android.dx.merge.InstructionTransformer.transform(InstructionTransformer.java:48)
    at com.android.dx.merge.DexMerger.transformCode(DexMerger.java:840)
    at com.android.dx.merge.DexMerger.transformMethods(DexMerger.java:811)
    at com.android.dx.merge.DexMerger.transformClassData(DexMerger.java:783)
    at com.android.dx.merge.DexMerger.transformClassDef(DexMerger.java:680)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:540)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
    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)

Anyone can help me with this problem? Thanks a lot.

If you're using Android Studio without gradle then Preferences->Compiler->Android Compilers->Force Jumbo Mode

If your using gradle then add to build.gradle

android {
    dexOptions {
       jumboMode true
    }

There's a limitation in Android on the number of Java methods you can have in a single dex file, and you're hitting that limit. Unfortunately, there's no easy solution to it. Your choices are:

  • Simplify your code. If you're using a lot of libraries, see if you can cut back on the number of libraries you're using. Some libraries have a lot of methods in them.
  • Use ProGuard even in your debug builds. ProGuard will strip out unused methods and can save a lot of space. To get started on ProGuard, look at these links:

If those approaches don't work, it's possible to split your application into multiple dex files and use classloader tricks to make it work at runtime, but that's more complicated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM