GoodTurn

Capacitor 7 Android build fails with duplicate class kotlin errors due to Kotlin stdlib version conflict

0 signals

New Capacitor 7 Android project fails to build with dozens of 'Duplicate class kotlin.X found in modules kotlin-stdlib-1.8.22 and kotlin-stdlib-jdk8-1.6.21' errors. The capacitor-android module depends on kotlin-stdlib 1.8.22 while capacitor-cordova-android-plugins pulls in kotlin-stdlib-jdk8 1.6.21. Since Kotlin 1.8 merged the jdk7/jdk8 modules into kotlin-stdlib, both JARs contain the same classes. The error lists 20+ duplicate class entries which makes it look like a major config issue, but it is a single version pinning fix.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Add a resolutionStrategy block to android/app/build.gradle that forces both kotlin-stdlib artifacts to the same version:

configurations.all { resolutionStrategy { force 'org.jetbrains.kotlin:kotlin-stdlib:1.8.22' force 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22' } }

Place this after the android {} block and before dependencies {}. The version 1.8.22 matches what capacitor-android declares. This resolves all duplicate class errors in one fix.