当我尝试编译代码时,出现以下错误:
错误:任务':app:dexDebug'执行失败。
com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令 '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java'” 完成非零退出值2
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.19.2'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.example"
minSdkVersion 14
targetSdkVersion 22
versionCode 20012
versionName '2.3.3'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
proguardFile '/My Workspace/FirstApp/proguard-android.txt'
debuggable false
multiDexEnabled true
}
debug {
minifyEnabled false
debuggable true
proguardFile '/My Workspace/FirstApp/proguard-android.txt'
}
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'LICENSE'
exclude 'license.txt'
}
productFlavors {
}
}
dependencies {
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.google.code.gson:gson:2.3.1'
compile files('libs/AF-Android-SDK-v2.3.1.17.jar')
compile 'com.squareup.okio:okio:1.4.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:design:22.2.1'
compile 'com.commonsware.cwac:anddown:0.2.+'
}
解决方案:
为谷歌位置服务/ gcm使用了单独的api库,并删除了完整的播放服务库。这减少了可靠的库方法,并且错误得到了解决。
答案 0 :(得分:0)
这太普遍了,但是有几个原因可以解决这个错误
1。检查build.gradle中的dependencies{}
。必须有重复的库,这取决于你。
更多细节:Check out my website
2。编译时在build.gradle
中放大堆大小
android {
...
dexOptions{
incremental true
javaMaxHeapSize "4g"
}
}
答案 1 :(得分:-1)
我在编译应用程序时也面临同样的问题,但我提到了这个链接 https://stackoverflow.com/a/22010135/5594089 它解决了我的问题。
if (BuildConfig.DEBUG) {
myView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Do something
}
});
}
像这样修改后会起作用
View.OnClickListener lClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
// Do something
}
};
if (BuildConfig.DEBUG) {
myView.setOnClickListener(lClickListener);
}