Skip to content
Latchkey

Android "Duplicate class" in CI

Two dependencies bring the same class onto the classpath, so the Android build cannot decide which to use. Usually an old and a new artifact of the same library (or a renamed module) coexist.

What this error means

The build fails with "Duplicate class <name> found in modules ... and ...", naming two artifacts that both contain the class. It is deterministic and tied to your dependency graph.

Gradle output
Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules
kotlin-stdlib-1.8.0 and kotlin-stdlib-jdk8-1.6.0
Go to the documentation to learn how to <a>resolve dependency conflicts</a>.

Common causes

Two artifacts contain the same class

A library was split or renamed across versions (e.g. kotlin-stdlib-jdk8 merged into kotlin-stdlib), and both end up on the classpath.

Transitive version drift

Different dependencies pull different versions of a shared library, and the merged classpath contains duplicate classes.

How to fix it

Align versions with a BOM / platform

A platform constraint keeps related artifacts on one consistent version so duplicates disappear.

build.gradle.kts
dependencies {
  implementation(platform("org.jetbrains.kotlin:kotlin-bom:2.0.20"))
  // related kotlin artifacts now share one version
}

Exclude the redundant artifact

When one artifact is obsolete, exclude it from the dependency that drags it in.

build.gradle.kts
implementation("com.example:lib:1.0") {
  exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
}

How to prevent it

  • Use a BOM/platform to keep related artifacts on one version.
  • Run ./gradlew :app:dependencies to spot duplicate sources.
  • Avoid mixing split/renamed artifact variants of the same library.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →