- Error:Execution failed for task ':ttt:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
解决方案
-
Gradle 配置:app的build.gradle中
android { defaultConfig { applicationId "com.xxx.xxx" minSdkVersion 14 targetSdkVersion 21 multiDexEnabled true //加上这句话 } }
-
Gradle 配置:app的build.gradle中
dependencies { compile 'com.android.support:multidex:1.0.1' }
-
自己的Application 类重写方法:
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }
也可以继承android.support.multidex.MultiDexApplication类,不用重写上面方法
-
如果你的应用中包含引用的lirary工程或moudle,需要将预编译设置为false:
android { // ... dexOptions { preDexLibraries = false } }
当运行时如果看到如下错误:
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: Java heap space
在dexOptions中有一个字段用来增加java堆内存大小:
android {
// ...
dexOptions {
javaMaxHeapSize "2g"
}
}