question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Module with the Main dispatcher is missing with version 1.3.0-RC2 and other versions as well

See original GitHub issue

This crash has been haunting me occasionally for a few months now:

Fatal Exception: java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. ‘kotlinx-coroutines-android’ at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.missing + 90(MissingMainCoroutineDispatcher.java:90) at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.isDispatchNeeded + 71(MissingMainCoroutineDispatcher.java:71) at kotlinx.coroutines.DispatchedKt.resumeCancellable + 420(DispatchedKt.java:420) at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable + 26(CancellableKt.java:26) at kotlinx.coroutines.CoroutineStart.invoke + 109(CoroutineStart.java:109) at kotlinx.coroutines.AbstractCoroutine.start + 154(AbstractCoroutine.java:154) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch + 54(BuildersKt__Builders_commonKt.java:54) at kotlinx.coroutines.BuildersKt.launch + 1(BuildersKt.java:1) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default + 47(BuildersKt__Builders_commonKt.java:47) at kotlinx.coroutines.BuildersKt.launch$default + 1(BuildersKt.java:1) at com.example.user.ui.screens.mapScreen.MapActivity$getLocation$1.onChanged + 667(MapActivity.java:667) at com.example.user.ui.screens.mapScreen.MapActivity$getLocation$1.onChanged + 46(MapActivity.java:46) at androidx.lifecycle.LiveData.considerNotify + 131(LiveData.java:131) at androidx.lifecycle.LiveData.dispatchingValue + 149(LiveData.java:149) at androidx.lifecycle.LiveData.setValue + 307(LiveData.java:307) at androidx.lifecycle.MutableLiveData.setValue + 50(MutableLiveData.java:50) at androidx.lifecycle.Transformations$1.onChanged + 76(Transformations.java:76) at androidx.lifecycle.MediatorLiveData$Source.onChanged + 152(MediatorLiveData.java:152) at androidx.lifecycle.LiveData.considerNotify + 131(LiveData.java:131) at androidx.lifecycle.LiveData.dispatchingValue + 149(LiveData.java:149) at androidx.lifecycle.LiveData.setValue + 307(LiveData.java:307) at androidx.lifecycle.MutableLiveData.setValue + 50(MutableLiveData.java:50) at com.example.user.domain.repository.location.LocationRepository.submitLocation + 95(LocationRepository.java:95) at com.example.user.domain.repository.location.LocationRepository.access$submitLocation + 18(LocationRepository.java:18) at com.example.user.domain.repository.location.LocationRepository$getLocation$callback$1.onLocationResult + 59(LocationRepository.java:59) at com.google.android.gms.internal.location.zzau.notifyListener + 4(zzau.java:4) at com.google.android.gms.common.api.internal.ListenerHolder.notifyListenerInternal + 17(ListenerHolder.java:17) at com.google.android.gms.common.api.internal.ListenerHolder$zaa.handleMessage + 5(ListenerHolder.java:5) at android.os.Handler.dispatchMessage + 106(Handler.java:106) at com.google.android.gms.internal.base.zap.dispatchMessage + 8(zap.java:8) at android.os.Looper.loop + 214(Looper.java:214) at android.app.ActivityThread.main + 6981(ActivityThread.java:6981) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 493(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main + 1445(ZygoteInit.java:1445)

This is the latest crash with coroutines version kotlinx-coroutines-android:1.3.0-RC2, AS 3.5, Gradle 5.1.1, AGP 3.4.2, R8 enabled, version 1.4.94. This particular crash happened on Samsung 9 running android 9, but i have also seen the crash (crashlytics) it on other versions and devices as well: Redmi 4x with android 7.1.2 and the following properties: AS 3.4.2, gradle 5.1.1, AGP 3.4.1

and on older versions of coroutines, this time bundled with core:kotlinx-coroutines-android:1.1.1, gradle 5.1.1 and AGP 3.4.1 on pocophone f1 running android 9, samsung j5 running android 8.1.0.

i have been unable to reproduce this issue on any of our production builds. I have also gone through all the issues related to MissingMainCoroutineDispatcher i could find here and on SO, yet none of the solutions seems to work. Some suggested that using -core as well -android might be related, but this happens as well without -core. Other suggested the packaging might get corrupted during when signing the app, but we have used the same build flow before without issues. i have also added the following proguard rules, while fully aware those are not required when using R8:

`# Coroutines

ServiceLoader support

-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {} -keepnames class kotlinx.coroutines.CoroutineExceptionHandler {} -keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {} -keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}

Most of volatile fields are updated with AFU and should not be mangled

-keepclassmembernames class kotlinx.** { volatile <fields>; }`

Also without any visible effect. I have also seen suggestions regarding the signing process and specifically the final production apk, and the META-INF/services folder - and it looks like this when i open the apk in AS: Screen Shot 2019-09-13 at 9 57 21 AM

So not sure when to go from here and what, and would appreciate any insights you may have on this.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
ispboxcommented, Sep 29, 2019

1.3.0 version works for me on Android, but 1.3.2 has the same error. I use android version of coroutines

"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2"

Nothing helps - only downgrade. The problem exist in debug build as well, so it is not connected with Proguard.

3reactions
qwwdfsadcommented, Nov 27, 2019

During this year 😃 The only blocker right now is fixing kotlinx-coroutines-test and then release is ready

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module with Main dispatcher is missing - Stack Overflow
Using just the kotlinx-coroutines-android version solves the problem.
Read more >
Change log for kotlinx.coroutines
Main not being fully initialized on Android and Swing (#3101). Version 1.6.0-RC3. Fixed the error in 1.6.0-RC2 because of which Flow.
Read more >
runtime NPE in Kotlin Coroutine Dispatcher - Issue Tracker
Kotlin Coroutines Version : 1.1.1. It throw this exception : Fatal Exception: java.lang.IllegalStateException: Module with the Main dispatcher is missing.
Read more >
WhatsNew 1.3 | Ktor Framework
Kotlin Server and Client Framework for microservices, HTTP APIs, and RESTful services.
Read more >
VERSION.txt - XRAY Subversion Server
readFrom + JETTY-345 fixed lost content with blocked NIO. ... Missing Request Dispatchers - Missing web.xml based configuration - Missing war support ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found