Skip to content
FR
  1. LuzineDebug
  2. Mobile (Android, iOS)
  3. Duplicate class kotlin.collections.jdk8.Collecti…
Mobile (Android, iOS) Intermediate ≈ 20 min to fix

Fix "Duplicate class ... found in modules" in an Android Gradle build

Error message
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)
In short

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.

Be the first to confirm this fix

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

  1. Misaligned Kotlin versions: the project (often Flutter or React Native with an old kotlinVersion) uses an outdated Kotlin plugin while a recent dependency brings kotlin-stdlib 1.8+.
  2. Support Library and AndroidX mixed: an old library still depends on com.android.support:* while the app uses androidx.*.
  3. Two variants of the same artifact: bcprov-jdk15on and bcprov-jdk18on, guava and listenablefuture, or an SDK published under two different names.
  4. Library added twice: a .jar or .aar copied into libs/ (through fileTree) and the same library also declared as a Maven dependency.

Step-by-step fix

  1. Read both modules involved

    The message names two group:name:version coordinates. Note the oldest or least expected one: that is the one to align or exclude.

  2. Find what pulls the dependency

    Print the app dependency tree, then look for the exact path to the offending module. On Windows, replace ./gradlew with .\gradlew (PowerShell) or gradlew.bat. For Flutter and React Native, run it from the android/ folder.

    bash
    ./gradlew :app:dependencies --configuration debugRuntimeClasspath
    ./gradlew :app:dependencyInsight --dependency kotlin-stdlib-jdk8 --configuration debugRuntimeClasspath
  3. Kotlin case: update the Kotlin plugin

    This is the real fix: a Kotlin plugin 1.8 or newer automatically aligns kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8 with the kotlin-stdlib version. Flutter: android/settings.gradle.kts; React Native: kotlinVersion in android/build.gradle. Pick a version compatible with your AGP and framework.

    kotlin
    // android/settings.gradle.kts (Flutter)
    plugins {
        id("org.jetbrains.kotlin.android") version "2.2.20" apply false
    }
  4. 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: every kotlin-stdlib* library gets the same version and the jdk8 classes are no longer duplicated.

    kotlin
    dependencies {
        implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.22"))
    }
  5. 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.

    kotlin
    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")
    }
  6. Support Library / AndroidX case

    If a library still depends on com.android.support, first look for a version that uses AndroidX. Meanwhile, enable Jetifier in gradle.properties: it rewrites those dependencies to AndroidX at build time (a deprecated option that slows the build).

    ini
    android.useAndroidX=true
    android.enableJetifier=true
  7. Clean and rebuild

    Delete the build outputs and run the check task again to confirm that no class is duplicated anymore.

    bash
    ./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.toml catalog and use BOMs (Kotlin, Firebase, Compose) so libraries from the same family stay aligned.
  • Avoid copying .jar files into libs/ 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

All Mobile (Android, iOS) errors →