Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
    }
like image 377
jchristof Avatar asked Oct 31 '18 20:10

jchristof


People also ask

Is Kotlin coroutines stable?

Coroutines were already available in previous Kotlin releases, but version 1.3 makes them stable, meaning that their API will not change in future releases.

Are coroutines still experimental?

UPDATE: Kotlin coroutines are no longer experimental as of Kotlin 1.3. Kotlin coroutines can and should be used in production. That was the chief reason to officially release them in Kotlin 1.1.

Are coroutines production ready?

Coroutines have been with us since Kotlin 1.1 as an experimental feature. But Kotlin 1.3 released the final API, and now they are production ready.

Are Kotlin coroutines parallel?

Kotlin's Coroutines enabling you to write parallel code easily, in a sequential way, and without worrying about the contextual overheads you know from using threads in Java.


3 Answers

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.

like image 83
Kiskae Avatar answered Sep 27 '22 21:09

Kiskae


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

like image 37
Dmitry Sokolov Avatar answered Sep 27 '22 21:09

Dmitry Sokolov


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**.

like image 24
ayvazj Avatar answered Sep 27 '22 21:09

ayvazj