ErrorDuplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.0

问题描述 投票:0回答:1

我使用 jetpack compose 和 kotlin,当我添加新的依赖项(我不知道哪个导致错误)在我同步依赖项并运行应用程序后,出现如下错误,我不知道为什么

  • 出了什么问题: 任务 ':app:checkDebugDuplicateClasses' 执行失败。

执行com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable时出现故障 在模块 kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) 和 kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin) 中找到重复的类 kotlin.collections.jdk8.CollectionsJDK8Kt :kotlin-stdlib-jdk8:1.7.10)

我不知道为什么会出现这个错误。运行应用程序时出错。

这是我的模块级依赖:

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'
}

这是我的项目级依赖

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

}

这是我的 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
    }
}

这是我的 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()
    }
}
firebase kotlin firebase-authentication dependencies android-jetpack-compose
1个回答
0
投票

那是因为你的一个依赖项已经在使用 Kotlin 1.8,而你的项目仍在使用 1.7。

如果你搞不清楚是哪个依赖,你可以升级你的项目使用Kotlin 1.8。这样做应该是安全的,因为没有重大的重大变化(请参阅Kotlin 1.8.0 发行说明兼容性指南)。

buildscript {
    dependencies {
        // ...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
    }
}
plugins {
    // ...
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
    // ...

}
© www.soinside.com 2019 - 2024. All rights reserved.