我正在尝试在Android设备和模拟器上运行项目。但不幸的是我遇到了两个错误。
错误1:
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
错误2:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
答案 0 :(得分:1)
我前段时间遇到过你的第一个问题。我在multiDexEnabled true
中使用defaultConfig
解决了这个问题。你应该尝试一下!
答案 1 :(得分:0)
在build.gradle中:
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
然后,您需要从MultiDexApplication
扩展您的应用程序类,或将此代码段包含在其中:
public class YouApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Here是官方指南。