无法访问'androidx.lifecycle.LifecycleCoroutineScope'的超类型kotlinx.coroutines.CoroutineScope [英] Cannot access 'kotlinx.coroutines.CoroutineScope' which is a supertype of 'androidx.lifecycle.LifecycleCoroutineScope'

查看:24
本文介绍了无法访问'androidx.lifecycle.LifecycleCoroutineScope'的超类型kotlinx.coroutines.CoroutineScope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用房间API,但必须处理异步任务,您知道为什么。 我选择了Kotlin协程和androidx。生命周期。尝试编写一些代码,但在IDE中显示2个错误

无法访问‘kotlinx.coroutines.CoroutineScope’,它是‘androidx.lifecycle.LifecycleCoroutineScope’的超类型。检查模块类路径中是否存在丢失或冲突的依赖项 无法访问类‘kotlinx.coroutines.Job’。检查模块类路径中是否存在丢失或冲突的依赖项 error

这是我的Gradle模块

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'

}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.jacksafblaze.sqlitedemo"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildFeatures{
        viewBinding 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'
    }
}

dependencies {
    implementation "androidx.room:room-ktx:2.3.0"
    implementation "androidx.room:room-runtime:2.3.0"
    kapt "androidx.room:room-compiler:2.3.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
    implementation'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
    implementation'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:5'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

和Gradle项目

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我尝试使缓存无效并重新启动,从头开始重新创建应用程序,然后重新安装Android Studio,但我仍然收到此错误。

‘org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0’升级到推荐答案

‘org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-RC’和一切正常

这篇关于无法访问'androidx.lifecycle.LifecycleCoroutineScope'的超类型kotlinx.coroutines.CoroutineScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆