Problem with duplicate class com.google.android.gms Android Studio

Viewed 12732

i have a problem with : Duplicate class com.google.android.gms.common.api.zza found in modules classes.jar (com.google.android.gms:play-services-base:9.4.0) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)

Have you idea for resolve this error ?

I give you my app bluid.gradle ....

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'
apply plugin: 'com.google.gms.google-services'

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

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

android {
    compileSdkVersion 23
    defaultConfig {
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        applicationId "fr.appli.test"
        minSdkVersion 16
        targetSdkVersion 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test:runner:0.5') {
        exclude group: 'com.android.support', module: 'support-annotations'
        implementation 'com.google.android.gms:play-services-ads:17.2.0'
    }
    androidTestImplementation 'com.android.support.test:rules:0.4'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
    androidTestImplementation ('com.android.support.test.espresso:espresso-contrib:2.2') {
        exclude module: 'support-annotations'
        exclude module: 'support-v4'
        exclude module: 'support-v13'
        exclude module: 'recyclerview-v7'
    }
    androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
    androidTestImplementation 'com.android.support:support-annotations:23.4.0
    implementation 'com.android.support:preference-v14:23.4.0'
    implementation 'com.android.support:design:23.4.0'
    implementation 'com.android.support:cardview-v7:23.4.0'
    implementation 'com.android.support:recyclerview-v7:23.4.0'
    implementation 'com.google.android.gms:play-services-location:9.4.0'
    implementation 'com.google.android.gms:play-services-maps:9.4.0'
    implementation 'com.adobe.xmp:xmpcore:5.1.2'
    implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.4.1'
    implementation('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
    }
}

Thanks in advance for your help

4 Answers

You are using old versions of these

implementation 'com.google.android.gms:play-services-location:9.4.0'
implementation 'com.google.android.gms:play-services-maps:9.4.0'

try these newer versions

implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'

In the app's "build.gradle" file, add the following along with "android {...}"

configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-basement:16.0.`'
    }
}

Such errors are easily resolved by bumping the version of your libraries to the latest ones.

I can see that you're using super outdated versions of following libraries:

implementation 'com.google.android.gms:play-services-location:9.4.0'
implementation 'com.google.android.gms:play-services-maps:9.4.0'

Bump up their versions, and versions of all the other libraries and that should fix the error.

Latest version of both the libraries is 16.0.0, so you should make it

implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'

If after you updated your libraries as previous users have suggested, you keep seeing the same error, try excluding the duplicate module from one of your libraries. For example:

implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'{
        exclude group : 'nameOfTheGroupHere', module: 'nameOfTheModuleHere'
    }
Related