DEV Community

Code Green
Code Green

Posted on • Edited on

Duplicate class in Kotlin Android

You might get error for duplicate class in kotlin on a new Android project.

Error while gradle build:

Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)

Solution:

in build.gradle (Project level)

change kotlin.android to 1.8.0

plugins {
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}
Enter fullscreen mode Exit fullscreen mode

If you are using Jetapack Compose, this doesn't end here. You will get another error for compose:

This version (1.3.2) of the Compose Compiler requires Kotlin version 1.7.20 but you appear to be using Kotlin version 1.8.0 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).

To fix this you will have to change kotlinCompilerExtensionVersion version to 1.4.1

composeOptions {
        kotlinCompilerExtensionVersion '1.4.1'
    }
Enter fullscreen mode Exit fullscreen mode

Google has already listed down the Compose to Kotlin Compatibility Map
Link here: https://developer.android.com/jetpack/androidx/releases/compose-kotlin

Follow for more such guides.

Top comments (0)