Max
Max

Reputation: 29

I can't import coroutines into kotlin code

I am trying to delay a task by 1 second using coroutines but when I try importing kotlinx.coroutines.* it says unresolved reference.

Upvotes: 2

Views: 2138

Answers (2)

Andy Romero
Andy Romero

Reputation: 615

If you use IntelliJ IDEA, you can do the following:

1 - File -> Project Structure

Project Structure

2 - In the side menu go to "Modules" and you will have the option to "Add -> Library -> From Maven".

From Maven

3 - Add these 2 Kotlin coroutines libraries:

  • org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4
  • org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4

and select the checkboxes: "Download To" + "Transitive Dependencies" + "Sources".

Kotlin coroutines libraries

4 - After this all the dependencies of the coroutines in Kotlin are downloaded and compiled.

Note: If you want to see the latest versions of the Kotlin coroutines you can go directly to:

https://github.com/Kotlin/kotlinx.coroutines/blob/master/README.md#using-in-your-projects

Upvotes: 1

CoolMind
CoolMind

Reputation: 28865

In build.gradle of app folder you should add these libraries:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2'
}

Upvotes: 2

Related Questions