I’m trying to get coroutines to work in a multiplatform project, and I really need some assistance.
The project is using 1.4-M2, and if I add the following to the jvmMain section of build.gradle I can use runBlocking from jvmMain:
jvmMain {
dependencies {
// Other libraries goes here
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7")
}
}
However, if I add the same dependency to either commonMain or linuxMain, I still cannot access the package kotlinx.coroutines from the common or Linux code.
I found a discussion here: Support multi-threaded coroutines on Kotlin/Native · Issue #462 · Kotlin/kotlinx.coroutines · GitHub that suggests I should be using 1.3.5-native-mt-1.4-M1 instead, but doing so doesn’t change anything. I seem to be completely unable to access kotlinx.coroutines from antyhing other than the jvmMain code.
Note that I don’t really need to have multithreaded code in the native version. I’m perfectly fine with being limited to the JVM target for multithreading. However, I would need things like runBlocking to work, even if it doesn’t really do anything.
Based on what I can see when searching on this topic it should be possible, but I just can’t seem to get it to work.
What’s the proper solution for using coroutines in multiplatform projects?