duplicate entry: com/google/android/gms/internal/z

2019-07-20 04:01发布

问题:

In my project i have implemented play-services-games,first I have tried to add
compile 'com.google.android.gms:play-services:10.0.1'
but i got into some troubles and the solutions that i found was to compile only the needed library compile 'com.google.android.gms:play-services-games:10.0.1'
and all was great but when I've tried to add play-services-ads things got messy,I have added
compile 'com.google.android.gms:play-services-ads:10.0.1'
Now i get

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

Here is my build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.apps.fightersam"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile name: 'unity-ads', ext: 'aar'
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.google.android.gms:play-services-games:10.0.1'
    compile 'com.google.android.gms:play-services-ads:10.0.1'

    compile project(':BaseGameUtils')
}
repositories {
    flatDir {
        dirs 'libs'
    }
}

回答1:

You have to exclude the duplicate use of an internal transitive dependency. To find out which

gradle -q dependencies

This will give you the dependency tree. Then you can do something like

  compile('com.example.m:m:1.0') {
     exclude group: 'org.unwanted', module: 'x 
  }


回答2:

I was using the latest version of FirebaseUI 2.0.0 which seemed to be incompatible with google-services:3.0.0. Therefore I downgraded FirebaseUI version to 1.2.0 and added the following code to Project level build.gradle:

allprojects {
    repositories {
        jcenter()

        // Add the following
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
}


回答3:

I had a problem like this, but in my case I have two versions of the Google libraries being imported. In your case

delete this from your dependencies:

compile 'com.google.android.gms:play-services-ads:10.0.1'

Because it's imported from:

compile name: 'unity-ads', ext: 'aar'

Or do the opposite delet unity-ads and let compile 'com.google.android.gms:play-services-ads:10.0.1'

goodluck



回答4:

In my case Downgrading Both 'com.google.android.gms:play-services-games:10.0.1' and 'com.google.android.gms:play-services-ads:10.0.1'
To 'com.google.android.gms:play-services-games:9.0.1' and 'com.google.android.gms:play-services-ads:9.0.1' did the trick !