BugMedic

Android “Duplicate class found in modules”: exclude the transitive copy

Find both providers with ./gradlew app:dependencies, then exclude the transitive copy or align versions.

By BugMedic editorial teamLast source review: 2026-09-28Windows, macOS, Linux

Run ./gradlew :app:dependencies to find which declarations bring in each copy. Then exclude the transitive duplicate: implementation("com.lib:two:2.0") { exclude(group = "com.lib", module = "one") }, or align both on a single version.

Try these fixes in order

01

Find both providers

Print the runtime dependency tree and locate both artifacts named in the error to see which declarations pull them in.

./gradlew :app:dependencies --configuration debugRuntimeClasspath
02

Exclude the transitive duplicate

If one copy arrives transitively, exclude it from the dependency that drags it in, keeping the direct declaration.

03

Or align the versions

If the duplication is a version skew of the same library family, force a single version through the version catalog or a BOM.

04

Rebuild and confirm

Clean and rebuild; the duplicate-class error should be gone and the tree should show one provider.

./gradlew :app:assembleDebug

Interpret what you see

The error names two modules

What it suggests: The error names both modules providing the class. The dependency tree shows which of your declarations pulls each one in.

Next check: Run ./gradlew :app:dependencies and search for the two artifacts.

One provider looks like a repackaged copy

What it suggests: A common pattern: you declare library A directly while library B bundles the same classes inside its AAR.

Next check: Check whether one provider is a fat AAR you can replace with a modular dependency.

Mixed old and new versions of related libraries

What it suggests: Version catalogs and BOMs usually prevent this; the conflict often comes from a dependency added outside the catalog.

Next check: Align both providers on one version or exclude the transitive one.

Why this happens

  • Two dependencies ship the same class, usually because a library is included both directly and transitively.
  • A fat AAR bundles classes that another dependency also provides.

Still not working?

Do not enable packagingOptions pickFirsts for the duplicated class as a permanent fix; it hides which copy wins and can mask binary incompatibilities. Resolve the dependency duplication instead.

Official sources

These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.

Related Android Studio guides