Hello, I’m having a strange stack trace in a KMM p...
# compose-desktop
g
Hello, I’m having a strange stack trace in a KMM project (Android, iOS, Desktop):
Copy code
> Task :desktopApp:run
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'
...
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@71435f82, Dispatchers.Main[missing]]
Exception in thread "main" org.koin.core.error.InstanceCreationException: Could not create instance for [Factory:'com.expressus.domain.viewModels.ExpressusViewModel']
        at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:61)
        at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
        at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:111)
        at org.koin.core.scope.Scope.resolveValue(Scope.kt:237)
        at org.koin.core.scope.Scope.resolveInstance(Scope.kt:224)
        at org.koin.core.scope.Scope.get(Scope.kt:205)
But it only throws in desktop. More in 🧵
The code can be found here: https://github.com/GuilhE/Expressus branch main using Kotlin 1.6.10 works fine. Branch feature/kotlin-1.7.20-update fails (actually it fails starting in 1.6.21). I have no idea how to solve it, I’ve searched the web and nothing useful popped out. Maybe you can point me in the right direction. Thanks 🙏
All remaining dependencies can be in their last versions, except Kotlin
I’ve also asked in #koin but honestly i doubt it’s Koin’s fault because it works with Android and iOS and all share the same logic.
j
not sure if it's definitely the correct approach but what I did for one project was add following to
jvmMain
dependencies
Copy code
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:${Versions.kotlinCoroutines}")
g
It worked! Thank you so much @John O'Reilly this was driving me mad 😅
l
If I remember correctly, the core coroutines library doesn’t provide a main dispatcher by default on desktop. This is why you need to add the Swing module.