Unresolved reference kotlinx in Kotlin project
Asked Answered
I

1

1

This line:

import kotlinx.coroutines.*

Gives me Unresolved reference: kotlinx error.

My project creation process is very basic: In Intellij Idea: New project -> Kotlin -> JVM

My project structure:

project structure kotlin

Maybe I need to configure something somewhere?

SOLUTION:

I was creating my Kotlin app the wrong way. Finally I followed this tutorial: https://huongdankotlin.com/create-a-new-gradle-project-with-kolin-using-intellij.html

Then on kotlin (in src folder) -> new package -> kotlin file.

And then add implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-core", "1.5.2") inside dependencies in the build.gradle.kts

Now it worked for me.

Insulin answered 1/11, 2021 at 8:58 Comment(3)
Add this line implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-core", "1.5.2") inside dependencies in the build.gradle.kts file and sync your project.Guano
@GlennSandoval can you maybe take a look at my project structure? I dont have any of these files it seemsInsulin
It should be right in the root of your project folder.Guano
R
3

As mentioned in the Android documentation about coroutines you need to add the dependency to it in your gradle file to be able to use it like

dependencies {
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
}

EDIT: I missed that the question is not about an Android project. I'll leave the answer here as it might help android developers.

Rhinoplasty answered 1/11, 2021 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.