【问题标题】:Gradle build failed for android projectandroid项目的Gradle构建失败
【发布时间】:2017-03-06 09:03:51
【问题描述】:

我正在使用以下 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 依赖项的版本更改为不同的版本,但这也没有用。

【问题讨论】:

  • libs 文件夹中有东西吗?
  • @Egor no libs 文件夹为空。
  • 尝试过建筑/清洁项目?
  • 你能升级到firebase-messaging:10.2.0吗?
  • 伙计们,我认为问题在于apply plugin: 'com.google.gms.google-services' 的位置。将其放在build.gradle 的底部后,一切运行良好。

标签: android gradle


【解决方案1】:

我通过将这一行apply plugin: 'com.google.gms.google-services' 放在build.gradle 的底部而不是apply plugin: 'com.android.application' 的下方来解决了这个问题

【讨论】:

    【解决方案2】:

    尝试将此添加到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

    【讨论】:

    猜你喜欢
    • 2012-10-19
    • 2013-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 2020-03-04
    相关资源
    最近更新 更多