Search code examples
android-studiokotlinandroid-gradle-pluginkotlin-coroutinescoroutinescope

Cannot access 'kotlinx.coroutines.CoroutineScope' which is a supertype of 'androidx.lifecycle.LifecycleCoroutineScope'


Tried to use room api and had to deal with asynchronous tasks you know why. I chose kotlin coroutines and androidx.lifecycle. Tried to write some code and got 2 errors displaying in IDE

Cannot access 'kotlinx.coroutines.CoroutineScope' which is a supertype of 'androidx.lifecycle.LifecycleCoroutineScope'. Check your module classpath for missing or conflicting dependencies Cannot access class 'kotlinx.coroutines.Job'. Check your module classpath for missing or conflicting dependencies error

Here is my gradle module

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

and gradle project

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
}

I tried to invalidate caches and restart, to recreate app from scratch, and to reinstall android studio and I am still getting this error.


Solution

  • upgraded 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' to 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-RC' and everything works fine