skip to Main Content

i work with jetpack compose and kotlin, when i add new dependency (i don’t know which one cause error) after i sync dependency and run app, error like below, i don’t know why

  • What went wrong:
    Execution failed for task ‘:app:checkDebugDuplicateClasses’.

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)

I don’t know why this error. It’s error when I run the app.

This is my module level dependency :

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'com.google.dagger.hilt.android'
    id 'com.google.gms.google-services'

}

android {
    namespace 'com.haristudio.pdi_app'
    compileSdk 33

    defaultConfig {
        applicationId "com.haristudio.pdi_app"
        minSdk 23
        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 '1.2.0'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation "com.google.accompanist:accompanist-systemuicontroller:0.27.0"

    // Jetpack Compose
    def compose_version = "1.2.0"
    def kotlin_coroutines_version = "1.6.4"
    def dagger_version = "2.44.2"
    def compose_latest = "1.3.3"

    implementation 'androidx.activity:activity-compose:1.6.1'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_latest"
    implementation 'androidx.compose.material:material:1.3.1'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_latest"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_latest"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_latest"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
    implementation "androidx.navigation:navigation-compose:2.5.3"
    implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
    implementation 'androidx.compose.material:material-icons-extended:1.3.1'
    implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1"
    implementation "androidx.compose.runtime:runtime-livedata:1.3.3"
    implementation "androidx.compose.foundation:foundation:1.4.0-beta01"
    implementation "androidx.compose.runtime:runtime-rxjava2:1.4.0-beta01"
    //coil for images
    implementation "io.coil-kt:coil-compose:2.2.2"

    // exoPlayer
    implementation 'com.google.android.exoplayer:exoplayer:2.18.2'

    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"

    // Dagger Hilt
    implementation "com.google.dagger:hilt-android:$dagger_version"
    kapt "com.google.dagger:hilt-compiler:$dagger_version"

    // Firebase
    implementation platform('com.google.firebase:firebase-bom:31.2.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation "com.google.firebase:firebase-auth:21.1.0"
    implementation 'com.google.firebase:firebase-database:20.1.0'
}

This is my project level dependency

buildscript {
    ext {
        compose_ui_version = '1.2.0'
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.15'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
        classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"

    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.0' apply false
    id 'com.android.library' version '7.4.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
    id 'com.google.dagger.hilt.android' version '2.42' apply false
    id 'com.google.gms.google-services' version '4.3.14' apply false

}

This is my authViewModel

@HiltViewModel
class AuthViewModel @Inject constructor(
    private val repository : AuthRepository,
) : ViewModel() {
    private val _loginFlow = MutableStateFlow<Resource<FirebaseUser>?>(null)
    private val _signUpFlow = MutableStateFlow<Resource<FirebaseUser>?>(null)

    val loginFlow: StateFlow<Resource<FirebaseUser>?> = _loginFlow
    val signUpFlow: StateFlow<Resource<FirebaseUser>?> = _signUpFlow

    private val currentUser : FirebaseUser?
    get() = repository.currentUser

    init {
        if(currentUser != null){
            _loginFlow.value = Resource.Success(currentUser!!)
        }

    }

    fun login(email : String, password : String) = viewModelScope.launch {
        _loginFlow.value = Resource.Loading
       val result = repository.login(email,password)
        _loginFlow.value = result
    }
    fun signUp(
        username : String,
        email : String,
        password : String,
        numberPhone : String,
        image : String = "null",
        navController: NavController
    ) = viewModelScope.launch {
        _signUpFlow.value = Resource.Loading
        val result = repository.signUp(username,email,password,image,numberPhone)
        _signUpFlow.value = result
        if (result is Resource.Success) {
            navController.navigate("addNewTeam_screen")
        }
    }
    fun logout(){
        repository.logout()
        _loginFlow.value = null
        _signUpFlow.value = null
    }
}

this is my authrepositoryImpl

class AuthRepositoryImpl @Inject constructor(
    private val firebaseAuth: FirebaseAuth
) : AuthRepository {
    override val currentUser: FirebaseUser?
        get() = firebaseAuth.currentUser

    override suspend fun login(
        email: String,
        password: String
    ): Resource<FirebaseUser>  {
        return try {
            val result = firebaseAuth.signInWithEmailAndPassword(email,password).await()
            Resource.Success(result.user!!)
        }catch (e : Exception){
            Resource.Failure(exception = e)
        }
    }

    override suspend fun signUp(
        username: String,
        email: String,
        password: String,
        image: String,
        numberPhone: String
    ): Resource<FirebaseUser> {
        return try {
            val result = firebaseAuth.createUserWithEmailAndPassword(email, password).await()
            result?.
            user?.
            updateProfile(
                UserProfileChangeRequest
                    .Builder()
                    .setDisplayName(username)
                    .build()
            )?.await()
            Resource.Success(result.user!!)
        }catch (e : Exception){
            Resource.Failure(exception = e)
        }
    }

    override fun logout() {
        firebaseAuth.signOut()
    }
}

2

Answers


  1. That’s because one of your dependencies is already using Kotlin 1.8, while your project is still using 1.7.

    If you can’t figure out which dependency it is, you can upgrade your project to use Kotlin 1.8. It should be safe to do so since there are no major breaking changes (see Kotlin 1.8.0 release notes and compatibility guide).

    buildscript {
        dependencies {
            // ...
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
        }
    }
    plugins {
        // ...
        id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
        // ...
    
    }
    
    Login or Signup to reply.
  2. Try updating the kotlin android plugin to 1.8

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    plugins {
        id 'com.android.application' version '7.4.0' apply false
        id 'com.android.library' version '7.4.0' apply false
        id 'org.jetbrains.kotlin.android' version '1.7.0' apply false // change this to 1.8.0
        id 'com.google.dagger.hilt.android' version '2.42' apply false
        id 'com.google.gms.google-services' version '4.3.14' apply false
    

    }

    You dont need to change class path if on latest android studio

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search