Boris Dudelsack
01/12/2021, 6:53 PMrunBlocking
in linuxMain
and in macosMain
but i cannot use it wether in my own source set nativeMain
nor in commonMain
. Do i need add some sort of configuration to the source set?
plugins {
kotlin("multiplatform")
}
kotlin {
linuxX64("linux") {
binaries {
executable()
}
}
macosX64("macos") {
binaries {
executable()
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1-native-mt")
}
}
val nativeMain by creating {
dependsOn(commonMain)
}
val macosMain by getting {
dependsOn(nativeMain)
}
val linuxMain by getting {
dependsOn(nativeMain)
}
}
}
Boris Dudelsack
01/12/2021, 6:58 PMSam
01/12/2021, 7:02 PMexpect/actual
to define it in your common source set. The actual part on each platform can just be an alias.Marc Knaup
01/12/2021, 7:13 PMnativeMain
? 🤔Boris Dudelsack
01/12/2021, 7:31 PMrunBlocking
in commonMain
with following:
commonMain
expect fun <T> runBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T
linuxMain, macosMain
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking as runBlockingNative
import kotlin.coroutines.CoroutineContext
actual fun <T> runBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T = runBlockingNative(context, block)
But why cannot i just define/use it in nativeMain
?russhwolf
01/12/2021, 7:49 PMMichal Klimczak
01/12/2021, 8:57 PMAnimesh Sahu
01/13/2021, 3:57 AMMichal Klimczak
01/13/2021, 7:22 AMkotlin.mpp.enableGranularSourceSetsMetadata=true
? I have it enabled, but the problem persistsAnimesh Sahu
01/13/2021, 7:28 AMMichal Klimczak
01/13/2021, 8:31 AMshared
module (the one compiled for swift) but is messed up in another module.
• module1 (multiplatform)
• module2 (jvm, depends on module1)
• shared (multiplatform, depends on module1 and kapt-module2)
• settings.gradle for the whole project has the enableGranularEtc=true
And in module2 Android Studio says Unresolved reference
for classes from module1. Everything is fine in sharedArtyom Degtyarev [JB]
01/13/2021, 11:01 AMrunBlocking
is not available from common code is that it is not supported for the js target, as already mentioned. Expect/Actual mechanism use seems to be the best option. Related issues: https://github.com/Kotlin/kotlinx.coroutines/issues/195, https://github.com/Kotlin/kotlinx.coroutines/issues/1039, https://youtrack.jetbrains.com/issue/KT-29403Marc Knaup
01/13/2021, 11:02 AMnativeMain
mentioned before only consists of native targets.
https://kotlinlang.slack.com/archives/C3PQML5NU/p1610477636230700Artyom Degtyarev [JB]
01/13/2021, 11:29 AMBoris Dudelsack
01/18/2021, 1:28 PMkotlin.mpp.enableGranularSourceSetsMetadata=true
to the gradle.properties
seems to help.Animesh Sahu
01/18/2021, 1:29 PMAnimesh Sahu
01/18/2021, 1:31 PMjs
as target, you'd not get it on commonMain
, but on nativeMain
:)