PreCompose icon indicating copy to clipboard operation
PreCompose copied to clipboard

"Module with the Main dispatcher is missing" exception on Desktop build when using viewModelScope

Open cmota opened this issue 3 years ago • 1 comments

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")
  }
}

cmota avatar Jun 13 '22 23:06 cmota

It seems that the JVM target requires adding the org.jetbrains.kotlinx:kotlinx-coroutines-swing dependency, I will fix that.

Tlaster avatar Jun 14 '22 02:06 Tlaster

Closing as fixed

Tlaster avatar Sep 08 '22 01:09 Tlaster