Hi, I keep getting this error *`There is no event ...
# multiplatform
t
Hi, I keep getting this error
There is no event loop. Use runBlocking { ... } to start one.
from the iOS part, I use kotlin 1.4, coroutines 1.3.9 and my iOS dispatcher is based on this https://github.com/JetBrains/kotlinconf-app/blob/33f2d4e65f470d1444c5d4b46249af8feb243d03/common/src/iosMain/kotlin/org/jetbrains/kotlinconf/DispatcherNative.kt I have tried using native-mt with Dispatchers.Main but this gives me another error
Fatal exception in coroutines machinery for CancellableContinuation
The Android part works as expected. I have searched and tried a lot of solutions, but can't seem to figure out what's going wrong, any guidance is much appreciated 🙂
i
Try using coroutines
1.3.9-native-mt
instead
t
Hi Ivann, I tried using the native-mt but that gave me the
Fatal exception in coroutines machinery for CancellableContinuation
so unfortunately I'm still stuck, but thank you for the suggestion 👍
i
are you using ktor with your setup at all?
k
Confirm the app is on 1.4.0 of kotlin. If not, you’ll want another example (I’d humbly suggest: https://github.com/touchlab/KaMPKit)
Yeah, looks like latest commit on main branch is Dec 2019. That’s old for KMP
😅 1
k
Grade see 1.3.9 as need than 1.3.9-native-mt so if you have any transitive dependencies on 1.3.9 thats what it will use. Try forcing it to use native-mt
t
@Ivann Ruiz Yes I use Ktor This is my common dependencies, I believe they are all up to date?
Copy code
def coroutines_version = "1.3.9"
def ktor_version = "1.4.0"
def kodein_version = "7.1.0-master-88"
def serialization_version = "1.0.0-RC"
commonMain {
     
    dependencies {
        implementation(kotlin('stdlib-common'))
        implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:$serialization_version"
        implementation "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$serialization_version"
        implementation "io.ktor:ktor-client-json:$ktor_version"
        implementation "io.ktor:ktor-client-serialization:$ktor_version"
        implementation "io.ktor:ktor-client-logging:$ktor_version"
        implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
        implementation "org.kodein.di:kodein-di:$kodein_version"

    }
}
i
I see, had the same problem. Fixed it by downgrading Ktor to version
1.3.2-1.4.0-rc
k
ktor in 1.4 uses the mt version of coroutines
i
@kpgalligan Thanks for sharing this article, been wrestling with the issue for a few days. Glad it's not just me ha!
v
Hey, use native-mt and if you are using ktor logging feature disable it. It has some issue in LogLevel.All & LogLevel.Body.
👌 3
i
@Vinod Rai You hit it right on the spot! Couldn't figure out how to get Ktor
1.4.0
to work for me, works like a charm after disabling Logging. Had it set up as
LogLevel.All
👍 1
t
THANKS, changing to native-mt and ktor to loglevel.Info solved my problems, but raised a new problem, can someone explain why it's only Dispatchers.Main that works, when I try to use Dispatchers.Default nothing happens.
k
Ktor only works on main
m
That must be an iOS thing? You can use ktor on an IO dispatcher on e.g. android. Seems a bit odd, surely you dont want to do network calls on your main thread?
t
Thanks Kevin, I had another understanding after reading this
Copy code
You don't need to implement anything with -native-mt version:
For main thread use Dispatchers.Main
For background thread use Dispatchers.Default
from https://github.com/Kotlin/kotlinx.coroutines/issues/1889
👍 1
k
@Mgj the main thread restriction is an iOS thing for the ktor library. Not a general iOS networking thing, obviously. Also, to be clear, ktor calls are suspend functions. You start the call from the main thread, but that suspends to do the actual network call. Networking does not block the main thread. When completed, execution resumes on the main thread with the network response