Android:巨型模式与Multidex

我不完全确定将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)"} ... 

巨型模式 ,在阅读https://source.android.com/devices/tech/dalvik/dalvik-bytecode.html时 ,const-string / jumbo是string的巨型模式。 这是关于操作码这样“op vAA,string@ BBBBBBBB”与“op vAA,string@ BBBB”,32位与16位。

Multi Dex允许从多个dex文件中加载类。 主classes.dex必须包含调用此类方法所需的类。 在第一次调用MultiDex.install(Context)之后,在应用程序apk中find的次要dex文件将被添加到类加载器中请参阅https://developer.android.com/reference/android/support/multidex/MultiDex.html

看看这个(search巨型):

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

简而言之: – 与Android方法计数限制(64K)相似 – 对string计数(64K)有一个限制 – 为了克服这个限制,巨型模式通过使用特殊的opCode来引用超过2 ^ 16个string,使编码达到2 ^ 32个string。

在实践中: – 从我的经验来看(MultiDex&JumboMode)对apk安装时间有很大的影响(慢得多)。

希望这可以帮助:)