I'm having issues getting coroutines launching on ...
# multiplatform
p
I'm having issues getting coroutines launching on iOS on coroutines-1.3.5-native-mt. I'm getting the following error message when trying to run
Copy code
CoroutineScope(Dispatchers.Default).launch {
   ...
}
iOS output when calling from the main thread:
Copy code
kotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.
I'm running on iOS simulator, would that be the issue? I suspected a dependency versioning issue, so I am forcing coroutines version to be 1.3.5-native-mt via gradle as it seemed to be being force back to 1.3.5 without it, using the following in my root gradle:
Copy code
subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == "org.jetbrains.kotlinx" &&
                details.requested.name == "kotlinx-coroutines-core-common") {
                details.useVersion("$coroutinesVer")
            }
            if (details.requested.group == "org.jetbrains.kotlinx" &&
                details.requested.name == "kotlinx-coroutines-core") {
                details.useVersion("$coroutinesVer")
            }
        }
    }
}
and my dependencies tasks indicate the proper libs are being pulled in now. I'm really confused why I'm getting this error message. It was my understand that 1.3.5-native-mt utilizes a single background thread for Dispatchers.Default.
j
Could likely be that non
native-nt
version is being picked up as a transitive dependency.....running
./gradlew :common:dependencies
should show if that's the case (substitute with name of whatever your common module is)
you can use for example (
isForce
...or I think
strictly
is preferred now) in gradle to force use of particular version ....have example in https://github.com/joreilly/BikeShare/blob/master/common/build.gradle.kts
(actually just noticed from your original message that it seems like you've tried something like this already so not sure then in that case)
p
thanks.. it does sound like it is using the wrong lib version though, right? although Dispatchers.Main wouldn't be able to compile for iOS?
a
Your
Dispatchers.Main
for iOS may be missing a run loop. This thread has some useful information about the issue: https://github.com/Kotlin/kotlinx.coroutines/issues/470.