kotlinx.coroutines: java.lang.IllegalStateException: Module with the Main dispatcher is missing. Occurs for AWS device farm

For all devices in Amazon Web Service Device Farm we see crash evan for basi Android app which is using corutines 1.0.1 (implementation ‘org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1’). This totally block our ui testing

Caused by: java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android'
11-21 07:47:17.723 10755 10755 E AndroidRuntime: 	at kotlinx.coroutines.MissingMainCoroutineDispatcher.missing(Dispatchers.kt:123)
11-21 07:47:17.723 10755 10755 E AndroidRuntime: 	at kotlinx.coroutines.MissingMainCoroutineDispatcher.dispatch(Dispatchers.kt:116)
11-21 07:47:17.723 10755 10755 E AndroidRuntime: 	at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:282)
11-21 07:47:17.723 10755 10755 E AndroidRuntime: 	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:23)
11-21 07:47:17.723 10755 10755 E AndroidRuntime: 	at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
11-21 07:47:17.723 10755 10755 E AndroidRuntime: 	at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:160)
11-21 07:47:17.723 10755 10755 E AndroidRuntime: 	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54)
11-21 07:47:17.723 10755 10755 E AndroidRuntime: 	at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
11-21 07:47:17.723 10755 10755 E AndroidRuntime: 	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

You can find it here: https://github.com/int-mszczepanik/SampleAppForDeviceFarm

it crashes even when I run it manually via remote sessions on AWS (Samsung S5 (4.4.4)

This bug was also persistent for me, even not on AWS device. I fixed it by adding an additional line into my gradle file:

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'

Before, my gradle only contained a core library, but by adding android coroutine library this error was fixed. I see that in your sample project you have imported only android coroutine library, so add core lib too. It may fix the problem.