我们一直在努力应对65k方法的限制,并且已经完成了大多数优化。现在,我尝试添加Jacoco插件,并且再次遇到dex限制错误:

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)

但是,当我运行dex-method-count工具(在https://github.com/mihaip/dex-method-counts中找到)时,它说我们只有56k个方法。
Read in 56024 method IDs.
<root>: 56024
    : 4
    android: 10877
        accessibilityservice: 6
        ...

Jacoco库只有1309种方法(使用相同的dex-method-count工具进行计数),因此我们应该将其限制在65k以内。

有任何想法吗?还有其他人注意到dex-method-count工具报告的方法数量不足吗?

最佳答案

感谢@JesusFreke指出了这一点,事实证明限制是字符串的数量太大,而不是方法的数量。要将字符串数增加到2 ^ 32(而不是默认的2 ^ 16),请在build.gradle文件中启用jumboMode。

dexOptions {
        jumboMode = true
    }

有关字符串限制的更多信息,请参见What does 'String count' mean in Dex file Android?

关于android - 达到65k的Dex方法限制,但dex-method-count工具表示数量要少得多,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27427448/

10-12 02:20