Duplicate Class Error in kotlin gradle implementation

199 Views Asked by At

I get duplicate class errors as gradle implementation app's build.gradle file. But I don't know which implementation is actually a duplicate. How can i resolve this? Is there a better way like using bom for the dependencies?

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'

}

android {
    namespace 'com.example.bettehomes'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.bettehomes"
        minSdk 25
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version

            }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

        // Import the Compose BOM
    implementation 'com.google.android.gms:play-services-maps:18.1.0'
    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
    implementation 'androidx.activity:activity-compose:1.7.0-alpha04'
    implementation "androidx.compose.ui:ui-tooling:1.3.3"
    implementation "androidx.compose.ui:ui-tooling-preview:1.3.3"
    implementation 'androidx.compose.material3:material3:1.1.0-alpha04'
    // Android Studio Preview Support

    debugImplementation "androidx.compose.ui:ui-tooling:1.3.3"
    //testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.4.0-alpha05"
    debugImplementation "androidx.compose.ui:ui-test-manifest:1.3.3"
}
1

There are 1 best solutions below

5
Igor VANIAN On

I had this issue today and used gradle dependencies to figure out the dependency tree

I figured out that a lib used a latest version of appcompat which used kotlin 1.8.0, a version that has this issue.

In my case the fix was to add the kotlinVersion manually:

buildscript {
    ext {
        buildToolsVersion = "32.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 32
        androidXBrowser = "1.4.0"
        
        kotlinVersion = "1.8.0"
    }
...
}

For more information check this issue: https://github.com/proyecto26/react-native-inappbrowser/issues/398