Harikrishnan
Harikrishnan

Reputation: 8063

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry when building APK

I know this question is asked several times. I have been trying for over 3 hours with various solutions found but none of them worked for me.

When I run the application, it works well, but when I try to build APK it is giving me the following error:

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

I had taken the build successfully before I added firebase for FCM notification. After FCM was added, I had dex error, so I had to add support for multidex. I am also using YouTube player jar file.

This is my Gradle file:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.sample.application"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    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.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true;
    }
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.facebook.android:audience-network-sdk:4.+'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.android.support:multidex:1.0.1'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

Upvotes: 1

Views: 1587

Answers (1)

Bertrand Martel
Bertrand Martel

Reputation: 45503

The issue is that com.facebook.android:audience-network-sdk has dependency : play-services-ads:8.4.0 which doesn't match the 10.0.1 version

replace :

compile 'com.facebook.android:audience-network-sdk:4.+'
compile 'com.google.firebase:firebase-messaging:10.0.1'

with :

compile ('com.facebook.android:audience-network-sdk:4.+'){
    exclude group: "com.google.android.gms"
}
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'

Upvotes: 1

Related Questions