Hit 65k Dex, but dex-method-count tools say a lot less

We struggled with the 65k method prefix for a long time and have already done most of the optimizations. Now I am trying to add the Jacoco plugin and again I get the dex restriction error:

Error:Execution failed for task ':MyProject:dexExternalBetaDebug'. > com.android.ide.common.internal.LoggedErrorException: Failed to run command: /Users/orrieshannon/Code/sdk/sdk/build-tools/21.1.1/dx --dex --no-optimize --output /Me/MyProject/build/intermediates/dex/externalBeta/debug --input-list=/Me/MyProject/build/intermediates/tmp/dex/externalBeta/debug/inputList.txt Error Code: 2 Output: objc[80218]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexIndexOverflowException: Cannot merge new index 66105 into a non-jumbo instruction! at com.android.dx.merge.InstructionTransformer.jumboCheck(InstructionTransformer.java:109) at com.android.dx.merge.InstructionTransformer.access$800(InstructionTransformer.java:26) at com.android.dx.merge.InstructionTransformer$StringVisitor.visit(InstructionTransformer.java:72) 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:49) at com.android.dx.merge.DexMerger.transformCode(DexMerger.java:842) at com.android.dx.merge.DexMerger.transformMethods(DexMerger.java:813) at com.android.dx.merge.DexMerger.transformClassData(DexMerger.java:786) at com.android.dx.merge.DexMerger.transformClassDef(DexMerger.java:682) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:542) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302) at com.android.dx.command.dexer.Main.run(Main.java:245) at com.android.dx.command.dexer.Main.main(Main.java:214) at com.android.dx.command.Main.main(Main.java:106) 

However, when I run the count-de-method-count tool (found here https://github.com/mihaip/dex-method-counts ), it says that we are only with 56k methods.

 Read in 56024 method IDs. <root>: 56024 : 4 android: 10877 accessibilityservice: 6 ... 

The Jacoco library is just 1309 methods (counted using the same counter method), so we should be under 65k.

Any ideas? Has anyone else noticed that the dex-method-count tool underestimates the number of methods?

+7
android dex
source share
1 answer

Thanks to @JesusFreke for pointing it out, it turns out that the limit was in the number of lines too large, and not in the number of methods. To increase the number of lines to 2 ^ 32 (instead of the default value 2 ^ 16), include jumboMode in the build.gradle file.

 dexOptions { jumboMode = true } 

For more information on string constraints, see this post. What does “String count” mean in an Android Dex file?

+7
source share

All Articles