Search code examples
androidkotlinkotlinx.coroutines

Updating project to stable coroutines Kotlin 1.3.0 + Coroutines 1.0.0 error


I've specified the following in my project:

Module

dependencies {
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
  implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version'
}

Project

buildscript {
    ext.kotlin_version = '1.3.0'
    repositories {
        google()
        jcenter()
    }

dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

Wrapper

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

Gradle sync completes without errors, however each of my calls to

GlobalScope.launch {}

'launch' is marked with the following error:

'Unsupported [cannot use release coroutines with api version less than 1.3]'

I've invalidated and clean rebuilt - what am I missing?

**Edit

I can see where the error is generated:

kotlin/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt

fun checkCoroutinesFeature(languageVersionSettings: LanguageVersionSettings, diagnosticHolder: DiagnosticSink, reportOn: PsiElement) {
    if (languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)) {
        if (languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3) {
            diagnosticHolder.report(Errors.UNSUPPORTED.on(reportOn, "cannot use release coroutines with api version less than 1.3"))
        }
        return
    }

Solution

  • Clear you m2 cache and reimport all the dependencies. That should fix the issue. Reason being, if it was working before then you had all the dependencies you needed and by clearing your cache you refetch all required libraries needed to run coroutines.