今天做项目时突然遇到个这种异常,之前是没遇到过的。现在把这个异常写出来,希望能帮到也遇到同种情况的朋友!
注:我是用Android Studio开发的!
经典的:65536
Android Studio TransformException : Error:Execution failed for task ':app:transformClassesWithDexForDebug'
本来我这个项目一直都是好好的,代码也是没问题的。但是今天新加了个功能(当然也就新开启了个Activity....),然后再编译时用了好长时间,再然后就报上面的那个异常了!
详情信息如下:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_05\bin\java.exe'' finished with non-zero exit value 2
一开始以为是代码的问题,把代码检查了好几遍,都没发现问题。后来研究终于发现了问题原因:
If the number of method references in your app exceeds the 65K limit, your app may fail to compile.
(
如果你的应用程序的方法引用数量超过65 k的限制,应用程序可能无法编译。)
解决方法:
在“
build.gradle
: “中添加:
multiDexEnabled true
defaultConfig {
applicationId "com.welink2016.kmworknow"
minSdkVersion 17
targetSdkVersion 23
multiDexEnabled true
versionCode 3
versionName "1.3"
}
![]()