Android项目的Gradle构建失败

时间:2017-03-06 09:03:51

标签: android gradle

我正在使用以下build.gradle构建我的android项目

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.handyman.user"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/notice.txt'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:cardview-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'
    compile 'com.android.support:percent:25.1.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    testCompile 'junit:junit:4.12'
    compile 'com.github.ronaldsmartin:Material-ViewPagerIndicator:1.0.2'
    compile 'com.github.florent37:singledateandtimepicker:1.0.8'

    // retrofit essentials
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'

    // retrofit logging
    compile 'com.facebook.stetho:stetho:1.3.1'
    compile 'com.facebook.stetho:stetho-okhttp3:1.3.1'
    compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'

    compile 'uk.co.chrisjenx:calligraphy:2.2.0'

    compile 'com.google.firebase:firebase-messaging:10.0.1'

    compile 'com.android.support:multidex:1.0.1'
}

但我的构建失败了,

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/internal/zzv$zza$zza.class

在我的应用中启用了multidex。我尝试多次清理和重建项目没有任何结果,并尝试将firebase依赖项的版本更改为不同的版本,但这也没用。

2 个答案:

答案 0 :(得分:0)

尝试将其添加到build.gradle

android{


    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
        all*.exclude group: 'com.android.support', module: 'support-annotations'
    }

}

致谢:java.util.zip.ZipException: duplicate entry during packageAllDebugClassesForMultiDex

答案 1 :(得分:0)

我通过将此行apply plugin: 'com.google.gms.google-services'放在build.gradle的底部而不是apply plugin: 'com.android.application'

的下方来解决了这个问题
相关问题