最近鼓捣android,遇到一个很奇葩的问题。
gradle编译不报错,但是打包运行时,提示:Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with non-zero exit value 2。整体如下图:
各种折腾,翻墙。总算搞定。感谢万能的度娘,感谢谷哥。
先说说引起这个问题的原因:
如果你是一个android开发者,你至少听说过的Dalvik的蛋疼的64K方法限制。概括地说,在一个DEX文件,你可以调用很多的方法,但你只能调用它们最前面的65,536个 ,因为这是在方法调用集合中的所有的空间了。如果你的源代码和狂拽炫酷叼炸天的三方库中方法超过了这个限制。
解决方案:
1.
添加依赖于你的build.gradle支持MultiDex库
dependencies { ... compile 'com.android.support:multidex:' ... }
2.
在buildType或productFlavor中开启multiDexEnabled。
defaultConfig { ... multiDexEnabled true ... }
3.
在manifest中,设置你的application,name
<application
android :name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">