kotlinx.coroutines: IllegalStateException: Module with the Main dispatcher is missing

Our user with Xiaomi Redmi Note 4 device (Android 7.1.2) suddenly started to experience crash that had to be fixed with #657. We’re unable to reproduce it on our side. Here is reproducer app with the same lib dependencies as our main application: https://www.dropbox.com/s/eay696h9qmxjl5e/sample.zip?dl=1

AndroidX AppCompat: 1.0.0 Kotlin: 1.3.0 Coroutines: 1.0.0 Gradle wrapper: 4.10.2-bin

Caused by java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android'
       at kotlinx.coroutines.MissingMainCoroutineDispatcher.missing(Dispatchers.kt:123)
       at kotlinx.coroutines.MissingMainCoroutineDispatcher.dispatch(Dispatchers.kt:116)
       at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:279)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:23)
       at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
       at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:160)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54)
       at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
       at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
       at our.app.ui.base.BaseActivity.startAsync(BaseActivity.kt:229)
       at our.app.ui.main.MainActivity.refreshServerConfig(MainActivity.kt:63)
       at our.app.ui.main.MainActivity.onCreate(MainActivity.kt:134)
       at android.app.Activity.performCreate(Activity.java:6738)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2652)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2766)
       at android.app.ActivityThread.-wrap12(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6236)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)

About this issue

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

Most upvoted comments

I has same issue and fixed it by adding options from coroutines.pro to proguard. Hope it helps somebody.

For me updating Koltin to 1.3.50 and coroutines to 1.3.2 (having AGP 3.5.1) fixed the issue (I guess that it was initially broken by APG update or Dexguard update)

In our case, we put signingConfigs in the gradle file, then use the Generate Signed Bundle / APK to create the bundle. 😄 Removing the signingConfigs solves the problem.

I have the same issue. but the link is not available now. Could @evgentset provide again? please

I enabled R8 and it is the problem. Only proguard no problem. coroutines version 1.0.1