Question

Android: Duplicate class found in modules jetified-play-services-measurement and jetified-play-services-measurement-impl

I am trying to update the dependencies of one of my Android projects and I am getting this strange error.

The culprit is this line, for AdMob (I was previously using 20.6.0):

implementation "com.google.android.gms:play-services-ads:21.0.0"

I get a bunch of errors:

Duplicate class com.google.android.gms.internal.measurement.zzhx found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-20.1.1-runtime (com.google.android.gms:play-services-measurement-impl:20.1.1)

Duplicate class com.google.android.gms.internal.measurement.zzna found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-20.1.1-runtime (com.google.android.gms:play-services-measurement-impl:20.1.1)

Duplicate class com.google.android.gms.internal.measurement.zznb found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-20.1.1-runtime (com.google.android.gms:play-services-measurement-impl:20.1.1)

Duplicate class com.google.android.gms.internal.measurement.zznc found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-20.1.1-runtime (com.google.android.gms:play-services-measurement-impl:20.1.1)

...

Here are all the dependencies I'm using in the project's build.gradle (:app):

dependencies {
    implementation "androidx.recyclerview:recyclerview:1.2.1"
    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    // Firebase & Crashlytics
    implementation platform('com.google.firebase:firebase-bom:29.2.1')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    //Navigation
    implementation "androidx.navigation:navigation-fragment-ktx:2.4.2"
    implementation "androidx.navigation:navigation-ui-ktx:2.4.2"
    // AdMob
    implementation "com.google.android.gms:play-services-ads:21.0.0"
    // Style
    implementation 'com.intuit.sdp:sdp-android:1.0.5'
    // Play Core
    implementation 'com.google.android.play:core:1.10.3'
    implementation 'com.google.android.play:core-ktx:1.8.1'
    // Billing
    implementation "com.android.billingclient:billing-ktx:5.0.0"
}

And the dependencies in build.gradle (My App):

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.1.3"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
        classpath "com.google.gms:google-services:4.3.10"
        classpath "com.google.firebase:firebase-crashlytics-gradle:2.8.1"
    }
}

What is causing this error? If I revert play-services-ads to 20.6.0 I don't get any error.

Thank you for your help

 46  35055  46
1 Jan 1970

Solution

 118

you need also to update implementation platform('com.google.firebase:firebase-bom:29.2.1'), to

 implementation platform('com.google.firebase:firebase-bom:30.1.0')
2022-06-03

Solution

 118

you need also to update implementation platform('com.google.firebase:firebase-bom:29.2.1'), to

 implementation platform('com.google.firebase:firebase-bom:30.1.0')
2022-06-03

Solution

 18

As stated in the error message, there are some duplicate classes (most likely also having an incompatible version setting) that you need to resolve/remove. For my case I need to upgrade my Firebase Analytics. This was how I track down the problem:

I ran

./gradlew -q app:dependencies

to discover the following snippets by searching for play-services-measurement:

|    |    |    +--- com.google.android.gms:play-services-ads:21.2.0
|    |    |    |    +--- androidx.browser:browser:1.4.0
|    |    |    |    |    +--- androidx.collection:collection:1.1.0 -> 1.2.0 (*)
|    |    |    |    |    +--- androidx.concurrent:concurrent-futures:1.0.0 (*)
|    |    |    |    |    +--- androidx.interpolator:interpolator:1.0.0 (*)
|    |    |    |    |    +--- androidx.core:core:1.1.0 -> 1.8.0 (*)
|    |    |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    |    |    \--- com.google.guava:listenablefuture:1.0 -> 9999.0-empty-to-avoid-conflict-with-guava
|    |    |    |    +--- androidx.collection:collection:1.0.0 -> 1.2.0 (*)
|    |    |    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-base:21.2.0
|    |    |    |    |    \--- com.google.android.gms:play-services-basement:18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-identifier:18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-lite:21.2.0
|    |    |    |    |    +--- androidx.work:work-runtime:2.7.0 -> 2.7.1
|    |    |    |    |    |    +--- androidx.annotation:annotation-experimental:1.0.0 -> 1.1.0
|    |    |    |    |    |    +--- com.google.guava:listenablefuture:1.0 -> 9999.0-empty-to-avoid-conflict-with-guava
|    |    |    |    |    |    +--- androidx.lifecycle:lifecycle-livedata:2.1.0 -> 2.5.1 (*)
|    |    |    |    |    |    +--- androidx.startup:startup-runtime:1.0.0 -> 1.1.1 (*)
|    |    |    |    |    |    +--- androidx.core:core:1.6.0 -> 1.8.0 (*)
|    |    |    |    |    |    +--- androidx.room:room-runtime:2.2.5 -> 2.4.2 (*)
|    |    |    |    |    |    +--- androidx.sqlite:sqlite:2.1.0 -> 2.2.0 (*)
|    |    |    |    |    |    +--- androidx.sqlite:sqlite-framework:2.1.0 -> 2.2.0 (*)
|    |    |    |    |    |    +--- androidx.core:core:1.1.0 -> 1.8.0 (*)
|    |    |    |    |    |    \--- androidx.lifecycle:lifecycle-service:2.1.0 -> 2.4.0 (*)
|    |    |    |    |    +--- com.google.android.gms:play-services-ads-base:21.2.0 (*)
|    |    |    |    |    +--- com.google.android.gms:play-services-basement:18.0.0 (*)
|    |    |    |    |    +--- com.google.android.gms:play-services-measurement-sdk-api:20.1.2 (*)

|    +--- com.google.firebase:firebase-analytics:18.0.3
|    |    +--- com.google.android.gms:play-services-measurement:18.0.3
|    |    |    +--- androidx.collection:collection:1.0.0 -> 1.2.0 (*)
|    |    |    +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-ads-identifier:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-base:18.0.3 -> 20.1.2 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-impl:18.0.3
|    |    |    |    +--- androidx.collection:collection:1.0.0 -> 1.2.0 (*)
|    |    |    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-identifier:17.0.0 -> 18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-measurement-base:18.0.3 -> 20.1.2 (*)
|    |    |    |    \--- com.google.android.gms:play-services-stats:17.0.0
|    |    |    |         +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
|    |    |    |         \--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    \--- com.google.android.gms:play-services-stats:17.0.0 (*)
|    |    +--- com.google.android.gms:play-services-measurement-api:18.0.3
|    |    |    +--- com.google.android.gms:play-services-ads-identifier:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-base:18.0.3 -> 20.1.2 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-sdk-api:18.0.3 -> 20.1.2 (*)
|    |    |    +--- com.google.android.gms:play-services-tasks:17.0.0 -> 18.0.1 (*)
|    |    |    +--- com.google.firebase:firebase-common:19.3.0 -> 20.0.0 (*)
|    |    |    +--- com.google.firebase:firebase-components:16.0.0 -> 17.0.0 (*)
|    |    |    +--- com.google.firebase:firebase-installations:16.3.2 -> 17.0.0 (*)
|    |    |    +--- com.google.firebase:firebase-installations-interop:16.0.0 -> 17.0.0 (*)
|    |    |    \--- com.google.firebase:firebase-measurement-connector:18.0.0 (*)
|    |    \--- com.google.android.gms:play-services-measurement-sdk:18.0.3

So obviously the problem is laid within these two direct dependencies of my project com.google.android.gms:play-services-ads:21.2.0 and com.google.firebase:firebase-analytics:18.0.3 are both specifying a different version of play-services-measurement

If we look one step further at the pom file of play-services-measurement:18.0.3:

    <dependency>
      <groupId>com.google.android.gms</groupId>
      <artifactId>play-services-measurement-base</artifactId>
      <version>[18.0.3]</version>
      <scope>compile</scope>
      <type>aar</type>
    </dependency>
    <dependency>
      <groupId>com.google.android.gms</groupId>
      <artifactId>play-services-measurement-impl</artifactId>
      <version>[18.0.3]</version>
      <scope>compile</scope>
      <type>aar</type>
    </dependency>

It requires strictly 18.0.3 of base and impl which makes Gradle unable to resolve the problem by itself.

I've chosen to upgrade firebase analytics to 20.1.2 and the issue is resolved.

2022-10-26

Solution

 18

As stated in the error message, there are some duplicate classes (most likely also having an incompatible version setting) that you need to resolve/remove. For my case I need to upgrade my Firebase Analytics. This was how I track down the problem:

I ran

./gradlew -q app:dependencies

to discover the following snippets by searching for play-services-measurement:

|    |    |    +--- com.google.android.gms:play-services-ads:21.2.0
|    |    |    |    +--- androidx.browser:browser:1.4.0
|    |    |    |    |    +--- androidx.collection:collection:1.1.0 -> 1.2.0 (*)
|    |    |    |    |    +--- androidx.concurrent:concurrent-futures:1.0.0 (*)
|    |    |    |    |    +--- androidx.interpolator:interpolator:1.0.0 (*)
|    |    |    |    |    +--- androidx.core:core:1.1.0 -> 1.8.0 (*)
|    |    |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    |    |    \--- com.google.guava:listenablefuture:1.0 -> 9999.0-empty-to-avoid-conflict-with-guava
|    |    |    |    +--- androidx.collection:collection:1.0.0 -> 1.2.0 (*)
|    |    |    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-base:21.2.0
|    |    |    |    |    \--- com.google.android.gms:play-services-basement:18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-identifier:18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-lite:21.2.0
|    |    |    |    |    +--- androidx.work:work-runtime:2.7.0 -> 2.7.1
|    |    |    |    |    |    +--- androidx.annotation:annotation-experimental:1.0.0 -> 1.1.0
|    |    |    |    |    |    +--- com.google.guava:listenablefuture:1.0 -> 9999.0-empty-to-avoid-conflict-with-guava
|    |    |    |    |    |    +--- androidx.lifecycle:lifecycle-livedata:2.1.0 -> 2.5.1 (*)
|    |    |    |    |    |    +--- androidx.startup:startup-runtime:1.0.0 -> 1.1.1 (*)
|    |    |    |    |    |    +--- androidx.core:core:1.6.0 -> 1.8.0 (*)
|    |    |    |    |    |    +--- androidx.room:room-runtime:2.2.5 -> 2.4.2 (*)
|    |    |    |    |    |    +--- androidx.sqlite:sqlite:2.1.0 -> 2.2.0 (*)
|    |    |    |    |    |    +--- androidx.sqlite:sqlite-framework:2.1.0 -> 2.2.0 (*)
|    |    |    |    |    |    +--- androidx.core:core:1.1.0 -> 1.8.0 (*)
|    |    |    |    |    |    \--- androidx.lifecycle:lifecycle-service:2.1.0 -> 2.4.0 (*)
|    |    |    |    |    +--- com.google.android.gms:play-services-ads-base:21.2.0 (*)
|    |    |    |    |    +--- com.google.android.gms:play-services-basement:18.0.0 (*)
|    |    |    |    |    +--- com.google.android.gms:play-services-measurement-sdk-api:20.1.2 (*)

|    +--- com.google.firebase:firebase-analytics:18.0.3
|    |    +--- com.google.android.gms:play-services-measurement:18.0.3
|    |    |    +--- androidx.collection:collection:1.0.0 -> 1.2.0 (*)
|    |    |    +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-ads-identifier:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-base:18.0.3 -> 20.1.2 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-impl:18.0.3
|    |    |    |    +--- androidx.collection:collection:1.0.0 -> 1.2.0 (*)
|    |    |    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-identifier:17.0.0 -> 18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-measurement-base:18.0.3 -> 20.1.2 (*)
|    |    |    |    \--- com.google.android.gms:play-services-stats:17.0.0
|    |    |    |         +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
|    |    |    |         \--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    \--- com.google.android.gms:play-services-stats:17.0.0 (*)
|    |    +--- com.google.android.gms:play-services-measurement-api:18.0.3
|    |    |    +--- com.google.android.gms:play-services-ads-identifier:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-base:18.0.3 -> 20.1.2 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-sdk-api:18.0.3 -> 20.1.2 (*)
|    |    |    +--- com.google.android.gms:play-services-tasks:17.0.0 -> 18.0.1 (*)
|    |    |    +--- com.google.firebase:firebase-common:19.3.0 -> 20.0.0 (*)
|    |    |    +--- com.google.firebase:firebase-components:16.0.0 -> 17.0.0 (*)
|    |    |    +--- com.google.firebase:firebase-installations:16.3.2 -> 17.0.0 (*)
|    |    |    +--- com.google.firebase:firebase-installations-interop:16.0.0 -> 17.0.0 (*)
|    |    |    \--- com.google.firebase:firebase-measurement-connector:18.0.0 (*)
|    |    \--- com.google.android.gms:play-services-measurement-sdk:18.0.3

So obviously the problem is laid within these two direct dependencies of my project com.google.android.gms:play-services-ads:21.2.0 and com.google.firebase:firebase-analytics:18.0.3 are both specifying a different version of play-services-measurement

If we look one step further at the pom file of play-services-measurement:18.0.3:

    <dependency>
      <groupId>com.google.android.gms</groupId>
      <artifactId>play-services-measurement-base</artifactId>
      <version>[18.0.3]</version>
      <scope>compile</scope>
      <type>aar</type>
    </dependency>
    <dependency>
      <groupId>com.google.android.gms</groupId>
      <artifactId>play-services-measurement-impl</artifactId>
      <version>[18.0.3]</version>
      <scope>compile</scope>
      <type>aar</type>
    </dependency>

It requires strictly 18.0.3 of base and impl which makes Gradle unable to resolve the problem by itself.

I've chosen to upgrade firebase analytics to 20.1.2 and the issue is resolved.

2022-10-26