APK errors

Duplicate class error

Error text

Duplicate class org.jetbrains.kotlin.* found in modules kotlin-stdlib-1.8.0 and kotlin-stdlib-jdk8-1.6.0

Cause

The same class exists inside two libraries. Gradle cannot choose one and stops the build.

Step-by-step fix

  1. Find the two modules named in the error. Both ship the same class.
  2. Use dependencyInsight to see who pulls that library in.
  3. Drop the older one with exclude group: 'x', module: 'y', or force the newer version for everyone.
  4. For Kotlin add the kotlin-bom platform so every Kotlin piece shares one version.
  5. After the change run ./gradlew clean assembleDebug.

Example commands

./gradlew :app:dependencies --configuration releaseRuntimeClasspath > deps.txt
./gradlew :app:dependencyInsight --dependency kotlin-stdlib --configuration releaseRuntimeClasspath

How to prevent it

After adding a library, skim the dependencies output; repeated names stand out.

Author and license: Nibras Code