Sphere
Log in Join
☆ 12

duplicate class error after adding Firebase Analytics

Android, AGP 8.5, Kotlin 2.0. Added firebase-analytics 22.1.0 and now build fails: Duplicate class com.google.android.gms.internal.measurement.zzdf found in modules jetified-play-services-measurement-21.0.0-runtime and jetified-firebase-analytics-22.1.0-runtime. I use the BoM (firebase-bom 33.1.0). I thought the BoM aligned all versions. What is pulling the old play-services 21.0.0? I have been staring at this for two hours and the BoM is supposed to prevent exactly this. Something is clearly overriding it and I cannot see what.

⚑ Report

4 replies

☆ 0
R rust ·2026-10-24#1

BoM aligns Firebase versions but not always play-services transitively if another dependency pins an older play-services-measurement. Run ./gradlew :app:dependencies --configuration releaseRuntimeClasspath and search for play-services-measurement to find who is bringing 21.0.0. Then exclude it from that dependency. Start there before you start excluding things randomly.

⚑ Report
☆ 0
C cache32 ·2026-10-26#2

Found it, an old ads SDK was pulling play-services-measurement 21.0.0. Added implementation('com.ads.sdk:ads:3.2') { exclude group: 'com.google.android.gms', module: 'play-services-measurement' }. Build passed. The BoM was fine, just outranked by a hardcoded transitive. Took me a while to find the right dependency in that giant tree dump.

⚑ Report
☆ 0
C cache ·2026-10-29#3

Alternatively force the version resolution globally: resolutionStrategy.force 'com.google.android.gms:play-services-measurement:22.0.0'. But excluding the specific transitive is cleaner because you know where it came from. Forces can mask future conflicts. We usually prefer excludes over forces because a force hides the next conflict until production.

⚑ Report
☆ 0
P plastic17 ·2026-11-03#4

This is so common with Firebase plus ads SDKs that I now add the dependency tree check to my code review checklist whenever someone adds a Google library. Two minutes versus an afternoon of duplicate class whack-a-mole. Cheap insurance for a problem that always shows up at the worst time.

⚑ Report
Log in to reply.