小编Jac*_*Saf的帖子

无法访问“kotlinx.coroutines.CoroutineScope”,它是“androidx.lifecycle.LifecycleCoroutineScope”的超类型

尝试使用 room api 并且必须处理异步任务,你知道为什么。我选择了 kotlin 协程和 androidx.lifecycle。尝试编写一些代码并在 IDE 中显示 2 个错误

无法访问“kotlinx.coroutines.CoroutineScope”,它是“androidx.lifecycle.LifecycleCoroutineScope”的超类型。检查模块类路径是否缺少或冲突的依赖项无法访问类“kotlinx.coroutines.Job”。检查模块类路径是否存在缺少或冲突的依赖项 错误

这是我的 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 …
Run Code Online (Sandbox Code Playgroud)

kotlin android-studio android-gradle-plugin kotlin-coroutines coroutinescope

5
推荐指数
1
解决办法
3727
查看次数