Fix "Duplicate class ... found in modules" in an Android Gradle build
Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
- Execution failed for task ':app:checkDebugDuplicateClasses'. > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
- Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
- Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules guava-31.1-android (com.google.guava:guava:31.1-android) and listenablefuture-1.0 (com.google.guava:listenablefuture:1.0)
- Duplicate class org.bouncycastle.LICENSE found in modules bcprov-jdk15on-1.70 (org.bouncycastle:bcprov-jdk15on:1.70) and bcprov-jdk18on-1.78 (org.bouncycastle:bcprov-jdk18on:1.78)
Two dependencies of your app contain the same Java/Kotlin class, and Gradle refuses to package them together. For kotlin-stdlib-jdk8, align the Kotlin versions (recent Kotlin plugin or the kotlin-bom BOM); for other cases, find what pulls in the old library with ./gradlew :app:dependencies and exclude it.
What this error means
Before building the APK, the Android Gradle plugin runs the checkDebugDuplicateClasses task (or checkReleaseDuplicateClasses): it checks that no class appears in two different artifacts on the classpath, since only one would be kept at random. The message names both modules with their Maven coordinates. The most common case comes from Kotlin: since Kotlin 1.8.0, kotlin-stdlib already contains the classes of kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8. If a library still pulls an old 1.7.x kotlin-stdlib-jdk8 next to a 1.8+ kotlin-stdlib, the jdk8 classes are there twice. Same principle with the old Support Library next to AndroidX, or two variants of the same library.
Common causes
- Misaligned Kotlin versions: the project (often Flutter or React Native with an old
kotlinVersion) uses an outdated Kotlin plugin while a recent dependency bringskotlin-stdlib1.8+. - Support Library and AndroidX mixed: an old library still depends on
com.android.support:*while the app usesandroidx.*. - Two variants of the same artifact:
bcprov-jdk15onandbcprov-jdk18on,guavaandlistenablefuture, or an SDK published under two different names. - Library added twice: a
.jaror.aarcopied intolibs/(throughfileTree) and the same library also declared as a Maven dependency.
Step-by-step fix
-
Read both modules involved
The message names two
group:name:versioncoordinates. Note the oldest or least expected one: that is the one to align or exclude. -
Find what pulls the dependency
Print the app dependency tree, then look for the exact path to the offending module. On Windows, replace
./gradlewwith.\gradlew(PowerShell) orgradlew.bat. For Flutter and React Native, run it from theandroid/folder../gradlew :app:dependencies --configuration debugRuntimeClasspath ./gradlew :app:dependencyInsight --dependency kotlin-stdlib-jdk8 --configuration debugRuntimeClasspath -
Kotlin case: update the Kotlin plugin
This is the real fix: a Kotlin plugin 1.8 or newer automatically aligns
kotlin-stdlib-jdk7andkotlin-stdlib-jdk8with thekotlin-stdlibversion. Flutter:android/settings.gradle.kts; React Native:kotlinVersioninandroid/build.gradle. Pick a version compatible with your AGP and framework.// android/settings.gradle.kts (Flutter) plugins { id("org.jetbrains.kotlin.android") version "2.2.20" apply false } -
Kotlin case: force alignment with the BOM
If you cannot upgrade yet (pure Java module, third-party library), import the Kotlin BOM in
app/build.gradle.kts: everykotlin-stdlib*library gets the same version and thejdk8classes are no longer duplicated.dependencies { implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.22")) } -
Exclude the duplicate module
For an obsolete variant pulled by a single library, exclude it on that dependency. To exclude it project-wide, use
configurations.all. Then check that the app works: excluding assumes the other module really provides the same classes.dependencies { implementation("com.example:some-sdk:2.3.0") { exclude(group = "org.bouncycastle", module = "bcprov-jdk15on") } } configurations.all { exclude(group = "org.bouncycastle", module = "bcprov-jdk15on") } -
Support Library / AndroidX case
If a library still depends on
com.android.support, first look for a version that uses AndroidX. Meanwhile, enable Jetifier ingradle.properties: it rewrites those dependencies to AndroidX at build time (a deprecated option that slows the build).android.useAndroidX=true android.enableJetifier=true -
Clean and rebuild
Delete the build outputs and run the check task again to confirm that no class is duplicated anymore.
./gradlew clean ./gradlew :app:checkDebugDuplicateClasses ./gradlew :app:assembleDebug
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Keep the Kotlin plugin, AGP and Gradle up to date together, following your framework compatibility matrix (Flutter, React Native, Capacitor).
- Declare your versions in a
gradle/libs.versions.tomlcatalog and use BOMs (Kotlin, Firebase, Compose) so libraries from the same family stay aligned. - Avoid copying
.jarfiles intolibs/when the library exists on Maven: Gradle cannot resolve conflicts for local files.
Frequently asked questions
Why does the error appear right after adding a Flutter or React Native package?
The new package brought a more recent native dependency (often kotlin-stdlib 1.8+) that collides with an older version already there. Update the project Kotlin plugin or align versions with the BOM.
Can I just disable the duplicate class check?
That is not a good idea: only one of the two classes would be kept, which can cause NoSuchMethodError or runtime crashes. Remove the source of the duplicate instead.
What is the Groovy syntax (build.gradle)?
Same logic with single quotes: implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.22') and exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'.
Useful tools for this error
More Mobile (Android, iOS) errors
- Fix "SDK location not found" (ANDROID_HOME / sdk.dir) on Android
- Fix "CocoaPods could not find compatible versions for pod" on iOS
- Fix "Unable to load script" (index.android.bundle) in React Native
- Fix "Signing for "App" requires a development team" in Xcode
- Fix "INSTALL_FAILED_UPDATE_INCOMPATIBLE: signatures do not match" on Android
- Fix "cmdline-tools component is missing" and "Android license status unknown" (flutter doctor)
- Fix "Invariant Violation: "main" has not been registered" (React Native / Expo)