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
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 ofjcenter
or any other older library/repo and compatible withAndroidX
you won’t need Jetifier anymore, so either comment it out or remove it. This should possibly fix the problem.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
: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.
I am having the same issue and I fixed it by downgrading
play-services-ads
dependency like this. So you can try.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
:If you are not using firebase and still get this error, you can try excluding the offending classes directly in
app/build.gradle
: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 :
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,
And it won’t produce any duplication related errors with the play-services dependency.
Add this line
android.enableJetifier=true
to your gradle.properties