Gradle Build failed with an exception : java.exe&#

2019-02-21 02:41发布

问题:

build.gradle file:

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "xxxxx.com.myapp"
        minSdkVersion 9
        targetSdkVersion 22
        versionCode 3
        versionName "1.2"


    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.google.android.gms:play-services-ads:7.3.0'
    compile files('libs/libGoogleAnalyticsServices.jar')
}

Error Log:

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:dexDebug'.

    com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_51\bin\java.exe'' finished with non-zero exit value 2

回答1:

Try removing the following from your dependencies:

compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/libGoogleAnalyticsServices.jar')

If you look here, the Analytics API is already built into Google play services, so the two are conflicting.



回答2:

Sometimes this build failed error occures due to multidex problem. As per looking into your build script it does not seems that you need multidex enabling ture. But still you can try this because I can not say much just seeing your gradle build script.Use

    defaultConfig {
            applicationId "xxxxx.com.myapp"
            minSdkVersion 9
            targetSdkVersion 22
            versionCode 3
            versionName "1.2"
            // enable Mutidex.
            multiDexEnabled true


        }


回答3:

You are including libGoogleAnalyticsServices.jar twice. Based in the path, it will be include by the following line (which includes all jars in the libs directory) --

compile fileTree(dir: 'libs', include: ['*.jar'])

remove this line to avoid including the lib twice --

compile files('libs/libGoogleAnalyticsServices.jar')