我以前见过各种版本的dex erros,但这个版本是新的.清理/重启等无济于事.图书馆项目似乎完好无损,依赖似乎正确联系在一起.
Unable to execute dex: method ID not in [0, 0xffff]: 65536
Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536
Run Code Online (Sandbox Code Playgroud)
要么
Cannot merge new index 65950 into a non-jumbo instruction
Run Code Online (Sandbox Code Playgroud)
要么
java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
Run Code Online (Sandbox Code Playgroud)
tl;博士:Google的官方解决方案终于来了!
http://developer.android.com/tools/building/multidex.html
只有一个小提示,你可能需要这样做以防止在执行dex-ing时内存不足.
dexOptions {
javaMaxHeapSize "4g"
}
Run Code Online (Sandbox Code Playgroud)
还有一种巨型模式可以以不太可靠的方式解决这个问题:
dexOptions {
jumboMode true
}
Run Code Online (Sandbox Code Playgroud)
更新:如果您的应用程序很胖并且您的主应用程序中有太多方法,则可能需要按照应用程序重新设置应用程序
http://blog.osom.info/2014/12/too-many-methods-in-main-dex.html
我有一个相当大的Android应用程序,它依赖于许多库项目.Android编译器对每个.dex文件有65536个方法的限制,我超过了这个数字.
当你达到方法限制时,你可以选择两种途径(至少我知道).
1)缩小你的代码
2)构建多个dex文件(参见此博文)
我调查了两个并试图找出导致我的方法计数变得如此之高的原因.Google Drive API占据了Guava依赖的最大块,超过12,000.Drive API v2的总库存超过23,000!
我想我的问题是,你认为我该怎么做?我应该删除Google云端硬盘集成作为我应用的功能吗?有没有办法缩小API(是的,我使用proguard)?我应该采用多重dex路由(看起来相当痛苦,尤其是处理第三方API)?
我的团队和我继承了另一个团队的大型Android项目.据报道,包含所有包含库的整个应用程序有大约35000种方法.我们现在的任务是在应用程序中实现我们需要使用Protocol Buffers的新服务.
问题是生成的.jar文件包含所有必需的.proto文件,会创建另外35个方法,即70000个方法.如果您不知道,Android编译器每个.dex文件的限制为65536个方法.我们显然超过了这个限制,我们在尝试编译应用程序时遇到以下错误:
Unable to execute dex: method ID not in [0, 0xffff]: 65536
Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536
Run Code Online (Sandbox Code Playgroud)
是的,应用程序架构可能应该进行重组,但这需要时间.目前我们正试图找出解决方案来暂时解决这个问题.
有什么建议?
我试图在gradle中为我的项目设置jumboMode,它似乎能够解决以下DexIndexOverflowException:
com.android.dex.DexException:无法将新索引65536合并为非巨型指令!
DexIndexOverflowException:无法将新索引65772合并为非jumbo指令!
1)什么是jumboMode选项实际上在幕后做了什么?
android {
...
dexOptions {
jumboMode true
}
}
Run Code Online (Sandbox Code Playgroud)
2)我也注意到启用multi-dex也可以解决同样的问题,这两种方法之间的正确选择是什么?
android {
...
defaultConfig {
...
multiDexEnabled true
}
}
Run Code Online (Sandbox Code Playgroud) 其中一项新功能android studio 2.2 preview 1是APK Analyzer
,当您尝试它时,它会为您提供统计信息Defined Methods和Referenced Methods
示例输出:
这个dex文件用28823个方法定义了4118个类,并引用了35206个方法
当ICS问世时,引入了几个新的扩展宽度字节码.其中大部分是用于支持巨型ID的说明.以下是一些新的说明,取自我的ics/dalvik/opcode-gen/bytecode.txt:
#
# Extended-width opcodes
#
op 00ff const-class/jumbo 41c y type-ref continue|throw
op 01ff check-cast/jumbo 41c n type-ref continue|throw
op 02ff instance-of/jumbo 52c y type-ref continue|throw
op 03ff new-instance/jumbo 41c y type-ref continue|throw
op 04ff new-array/jumbo 52c y type-ref continue|throw
op 05ff filled-new-array/jumbo 5rc n type-ref continue|throw
op 06ff iget/jumbo 52c y field-ref continue|throw
...
Run Code Online (Sandbox Code Playgroud)
但是,在JB代码中,我找不到对这些新字节码的任何引用.在我的jellybean版本的bytecodes.txt中,最后一个操作码以0xfe结尾:
op fc +iput-object-volatile 22c n field-ref optimized|continue|throw
op fd +sget-object-volatile 21c y field-ref optimized|continue|throw
op fe +sput-object-volatile 21c n field-ref optimized|continue|throw
# unused: …Run Code Online (Sandbox Code Playgroud) 我正在进行代码审查,并告诉某人删除仅使用过一次的私有方法.他们说这没关系,因为dex count不会因私有方法引用而增加.这是真的?我无法通过简单的谷歌搜索找到答案.