错误:Gradle:任务':app:dexDebug'的执行失败。 >添加谷歌播放服务后

时间:2016-10-18 15:28:55

标签: android android-gradle build.gradle

更新 我做了Nitesh建议的更改,但仍然收到相同的错误。我更新了下面的代码,以显示我的build.gradle文件现在的样子

在我将compile 'com.google.android.gms:play-services:9.6.1'添加到我的依赖项后,尝试构建并运行我的应用时遇到此错误。

Error:Gradle: Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/jdk1.8.0_101/bin/java'' finished with non-zero exit value 1

我已经阅读了很多帖子,人们得到了同样的错误,但没有任何建议对我有用。如果我从build.gradle中删除compile 'com.google.android.gms:play-services:9.6.1',一切正常。显然,这不是一个选择

到目前为止,我已经尝试过:

  1. 清洁/重建项目
  2. multiDexEnabled true添加到defaultConfig
  3. 添加了dexOptions{incremental true javaMaxHeapSize "4g"
  4. 确保没有重复的库
  5. 这是我的完整应用级build.gradle文件

    buildscript {
        repositories {
            jcenter()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.2.3'
        }
    }
    apply plugin: 'com.android.application'
    
    repositories {
        jcenter()
        mavenCentral()
    }
    
    android {
        signingConfigs {
        }
        compileSdkVersion 24
        buildToolsVersion "24.0.3"
        defaultConfig {
            multiDexEnabled true
            applicationId "com.codebyjordan.ancientcityapp"
            minSdkVersion 16
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
        }
        dexOptions {
            incremental true
            javaMaxHeapSize "4g"
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:24.2.1'
        compile 'com.android.support:cardview-v7:24.2.1'
        compile 'com.android.support:recyclerview-v7:24.2.1'
        compile 'com.googlecode.json-simple:json-simple:1.1'
        compile 'com.squareup.okhttp3:okhttp:3.4.1'
        compile 'se.akerfeldt:okhttp-signpost:1.1.0'
        compile 'oauth.signpost:signpost-core:1.2.1.2'
        compile 'com.google.code.gson:gson:2.6.2'
        compile 'com.squareup.picasso:picasso:2.5.2'
        compile 'com.google.android.gms:play-services:9.6.1'
    }
    apply plugin: 'com.google.gms.google-services'
    

    这是我的项目级gradle文件

    buildscript {
        repositories {
            jcenter()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.2.3'
            classpath 'com.google.gms:google-services:3.0.0'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
            mavenCentral()
        }
    }
    

1 个答案:

答案 0 :(得分:0)

您需要在项目classpath 'com.google.gms:google-services:3.0.0'文件中添加build.gradle

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0'
    classpath 'com.google.gms:google-services:3.0.0'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

同时在 app 级别apply plugin: 'com.google.gms.google-services'文件的末尾添加build.gradle。并再次建立。

将此行放在app / build.gradle

的末尾
apply plugin: 'com.google.gms.google-services'