Daniele B

02/28/2023, 5:31 PM
I have a multiplatform project: Android and Desktop. I have defined the core coroutine package in `commonMain`:
on Android, the app works without the need of adding the android-specific coroutine package on
on Desktop, it gives me this error:
Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlin-coroutine-android' and ensure it has the same version as 'kotlin-coroutine-core'
what is the reason why on Android, the target specific package is not needed?

Alexander Pozdniakov

02/28/2023, 5:49 PM
I didn't work with multiplatform projects yet, but I suppose there are Android specific and desktop specific dependencies in your project. And some Android dependency itself depends on
so you have it implicitly in the project. However this is not the case for the desktop part of a project.

Daniele B

02/28/2023, 5:50 PM
good point, it makes sense, thanks!


02/28/2023, 11:47 PM
Dispatchers.Main is defined only contexts where there is a main dispatcher. In Android, the Main dispatcher is dispatcher dispatching coroutine to the UI thread of Android. In a desktop application, by default, there is no main dispatcher. To make it simple, if you don't have a UI in your app, you should not be using Dispatchers.Main (at least in the common code). If you have a UI, you should make sure to have the dependency that specifies Mian dispatcher for your UI framework. If, for example, you use swing to render the UI on desktop, you should add the swing dependency to your desktop dependencies. Read more here: