How do you fix "Duplicate class found in modules" in Android Gradle builds?

← Android answers

Two libraries on your classpath contain the same class. Find which ones with the Gradle dependency report, then exclude one or align their versions.

./gradlew :app:dependencies --configuration releaseRuntimeClasspath

The error message names the class and the two modules that contain it. Search the report for those modules to see which of your dependencies pulls each one in. Then pick one fix:

// build.gradle.kts
dependencies {
    implementation("com.example:library-a:2.1.0") {
        exclude(group = "com.example", module = "legacy-core")
    }
}
 
// Or force one version for every dependency
configurations.all {
    resolutionStrategy.force("com.example:core:2.1.0")
}

A common real-world case is the same library appearing under an old and a new coordinate, such as the Android Support libraries alongside AndroidX. Migrating fully to AndroidX removes that conflict.

Related questions

Start debugging smarter today

Try Bugsee for free — no commitments, no hidden fees.

Free sign upLive demoNo credit card required