安卓:巨型模式 vs 多dex

2022-09-01 18:56:49

我不完全确定将dex选项“jumbomode”设置为true与添加multidex支持有什么区别。

将巨型模式设置为 true 或将 multidex 设置为 true 似乎可以解决以下问题

AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
AGPBI: {"kind":"SIMPLE","text":"com.android.dex.DexIndexOverflowException: Cannot merge new index 65772 into a non-jumbo instruction!","position":{},"original":"com.android.dex.DexIndexOverflowException: Cannot merge new index 65772 into a non-jumbo instruction!"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.InstructionTransformer.jumboCheck(InstructionTransformer.java:109)","position":{},"original":"\tat com.android.dx.merge.InstructionTransformer.jumboCheck(InstructionTransformer.java:109)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.InstructionTransformer.access$800(InstructionTransformer.java:26)","position":{},"original":"\tat com.android.dx.merge.InstructionTransformer.access$800(InstructionTransformer.java:26)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.InstructionTransformer$StringVisitor.visit(InstructionTransformer.java:72)","position":{},"original":"\tat com.android.dx.merge.InstructionTransformer$StringVisitor.visit(InstructionTransformer.java:72)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.io.CodeReader.callVisit(CodeReader.java:114)","position":{},"original":"\tat com.android.dx.io.CodeReader.callVisit(CodeReader.java:114)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.io.CodeReader.visitAll(CodeReader.java:89)","position":{},"original":"\tat com.android.dx.io.CodeReader.visitAll(CodeReader.java:89)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.InstructionTransformer.transform(InstructionTransformer.java:49)","position":{},"original":"\tat com.android.dx.merge.InstructionTransformer.transform(InstructionTransformer.java:49)"}
...

答案 1

巨型模式,当读取 https://source.android.com/devices/tech/dalvik/dalvik-bytecode.html 时,const-string/jumbo是字符串的巨型模式。它是关于操作码的,例如“op vAA,string@BBBBBBBB”与“op vAA,string@BBBB”,32位与16位。

多Dex是允许从多个dex文件加载类。主类.dex 必须包含调用此类方法所需的类。在应用程序apk中找到的辅助dex文件将在首次调用MultiDex.install(上下文)后添加到类加载器中,请参阅 https://developer.android.com/reference/android/support/multidex/MultiDex.html


答案 2

看看这个(搜索巨型):

https://developers.soundcloud.com/blog/congratulations-you-have-a-lot-of-code-remedying-androids-method-limit-part-1

简而言之: - 类似于Android方法计数限制(64K) - 字符串计数有限制(64K) - 为了克服此限制 - 巨型模式允许通过使用特殊操作码引用超过2 ^ 16个字符串,该操作码最多可以编码2 ^ 32个字符串。

在实践中: - 根据我的经验(MultiDex和JumboMode)都对apk安装时间有重大影响(慢得多)。

希望这有帮助:)


推荐