Home » Android » android – Updating project to stable coroutines Kotlin 1.3.0 + Coroutines 1.0.0 error

android – Updating project to stable coroutines Kotlin 1.3.0 + Coroutines 1.0.0 error

Posted by: admin June 15, 2020 Leave a comment

Questions:

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
    }
How to&Answers:

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.

Answer:

You’re missing the standard library in your dependencies. The plugin inspects that to figure out what version of the api to use.

Add "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" as a dependency to fix your error.

Answer:

Right click on project name -> Maven -> Reimport.
In my case it has helped.

Answer:

What worked for me with IntelliJ 2019.2.1 + Gradle

File => Project Structure

Then from the Project Settings Dialog select Modules and for each Kotlin module ensure the Language version and the API version matches. Unfortunately these settings get reset after every Gradle sync so you have to repeat the process after every Gradle sync.

enter image description here**.

Answer:

If you were ok before this, perhaps this is from one of your newly added dependencies. This was the case for me, I added an out-dated version of “squash” and got the very same error. After updating the “squash” to latest version everything is ok.