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.

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools πŸ”

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay