PreCompose
PreCompose copied to clipboard
"Module with the Main dispatcher is missing" exception on Desktop build when using viewModelScope
Hello!
This is working fine on Android, but I've noticed that if I compile my app for Desktop, the following call inside a ViewModel:
viewModelScope.launch {
_images.value = items
}
Will trigger the exception:
java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android'
I've managed to fix the issue by updating the build.gradle.kts file to:
val jvmMain by getting {
dependencies {
dependsOn(commonMain)
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.6.1")
}
}
It seems that the JVM target requires adding the org.jetbrains.kotlinx:kotlinx-coroutines-swing dependency, I will fix that.
Closing as fixed