skip to Main Content

I updated implementation com.google.android.gms:play-services-ads:19.8.0 to implementation com.google.android.gms:play-services-ads:20.4.0 and now I get this error:

Duplicate class com.google.android.gms.internal.measurement.zzbs found in modules jetified-play-services-measurement-18.0.2-runtime (com.google.android.gms:play-services-measurement:18.0.2) and jetified-play-services-measurement-sdk-api-18.0.3-runtime (com.google.android.gms:play-services-measurement-sdk-api:18.0.3)
Duplicate class com.google.android.gms.internal.measurement.zzl found in modules jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2) and jetified-play-services-measurement-sdk-api-18.0.3-runtime (com.google.android.gms:play-services-measurement-sdk-api:18.0.3)
Duplicate class com.google.android.gms.measurement.internal.zzfh found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgn found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgo found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgp found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgq found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzhs found in modules jetified-play-services-measurement-18.0.2-runtime (com.google.android.gms:play-services-measurement:18.0.2) and jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3)
Duplicate class com.google.android.gms.measurement.internal.zzhx found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)

How to fix this error?

5

Answers


  1. Best way to fix this and prepare your project for later is to migrate completely to AndroidX. First check if your project is ready, Refactor > Migrate to AndroidX. Once your project is independent of jcenter or any other older library/repo and compatible with AndroidX you won’t need Jetifier anymore, so either comment it out or remove it. This should possibly fix the problem.

    ...
    #android.enableJetifier=false
    ...
    

    In my case this wasn’t enough to solve the problem, if you still receive the same error but from a different library, it’s possibly because of other existing dependencies, avoid using bundled libraries or wildcard ones (in which system is left to guess) make sure you update them all and clean rebuild the project.

    If you still have to keep some conflicting library, try excluding individual classes to avoid the error like this from build.gradle:

    android {
        ...
        defaultConfig {
            ...
        }
        buildTypes {
            ...
        }
        configurations {
            all { // You should exclude one of them not both of them 
                exclude group: "com.android.support", module: "support-core-ui"
                exclude group: "com.android.support", module: "support-compat"
            }
        }
    }
    

    Official docs on module exclusion – Excluding transitive dependencies

    I also tried few more things before figuring the solution, like deleting .gradle from local machine, incase some old libraries got cached and causing the error, or resetting Android Studio, it just won’t work.

    Repo I tested the solution here, as you can see in this line I had to comment out the bundle module and specify latest updates to individual dependencies.

    You can read more on module dependency errors for reference.

    Login or Signup to reply.
  2. I am having the same issue and I fixed it by downgrading play-services-ads dependency like this. So you can try.

    def ads_version = "20.3.0"
    implementation "com.google.android.gms:play-services-ads:$ads_version"
    
    Login or Signup to reply.
  3. I ran into the same issue today, and after many trial and errors, I finally found that it was caused by a firebase dependency. If you’re using firebase in your project, make sure to use the latest BoM version in app/build.gradle:

    dependencies{
       // implementation platform('com.google.firebase:firebase-bom:25.12.0')  <-- Produces errors
      implementation platform('com.google.firebase:firebase-bom:29.0.0')  //<-- This works
    }
    

    If you are not using firebase and still get this error, you can try excluding the offending classes directly in app/build.gradle:

    android {
       defaultConfig {
        ...
       }
       buildTypes {
        ...
       }
    
       configurations {
         all {
           exclude group: "com.google.android.gms", module: "play-services-measurement-impl"
           exclude group: "com.google.android.gms", module: "play-services-measurement"
         }
       }
    }
    
    Login or Signup to reply.
  4. The error is being produced due to the conflicts between firebase & google service dependency. So you have 2 options.

    You can change the versions and keep doing that until you find the perfect working combination which is time consuming or you can find a solution that works every time so you don’t have to play with the versions every time. You just use that solution wherever you get such error.

    Here, you need to use the updated method of injecting the firebase dependency as shown in the official documentation.

    Put this line in your dependency :

    implementation platform('com.google.firebase:firebase-bom:28.1.0')
    

    Then, You can use any firebase dependency without specifying the versions, and it will work flawlessly all the time!

    The final code looks like this,

    implementation platform('com.google.firebase:firebase-bom:28.1.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-config'
    implementation 'com.google.firebase:firebase-crashlytics'
    

    And it won’t produce any duplication related errors with the play-services dependency.

    Login or Signup to reply.
  5. Add this line android.enableJetifier=true to your gradle.properties

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search