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.

Android "Module with the Main dispatcher is missing" (v1.3.2)

See original GitHub issue

Hello, yesterday I ran into a strange bug and i am hereby reporting its details. I have a simple android application written entirely in Kotlin, taking advantage of Coroutines features. Yesterday night I have updated the org.jetbrains.kotlinx:kotlinx-coroutines-android dependency to version 1.3.2, from 1.3.1 (Along with other external libraries, such as Firebase Remote Config from 19.0.1 to 19.0.2, and changing the app version code from 70 to 71). I run the app in debug config on my device (Samsung Galaxy S6 Edge with Custom Rom LineageOS 16.0 Android 9) and it just crashes before even showing the actual Activity content.

I checked the logcat, that reported a crash on the coroutine side, throwing the error “Missing Main dispatcher, include a library that actually contains one.”

? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.andreacioccarelli.turbounfollow, PID: 22509
    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(MainDispatchers.kt:90)
        at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.isDispatchNeeded(MainDispatchers.kt:71)
        at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:420)
        at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
        at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
        at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:154)
        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)

Everything checks out, except for the fact that that I do include an actual coroutine dependency, which seems to be flawed.

    // Kotlin
    implementation(
        kotlin("stdlib", KotlinCompilerVersion.VERSION)
    )

    implementation("org.jetbrains.anko:anko-sdk21:0.10.8")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2")

I downgraded the version, and the problem was there, again, with 1.3.1. I start to think about possible issues, but nothing comes to my mind.

I do not exactly remember what I did then, but since I use VCS i just discarded the modifications to my build.gradle.kts file, I reinstalled and it was working normally. I bump up the version to 1.3.2 and it does work fine. Really perplexed, I built a release apk and I push it over the beta channel, I went to sleep and the next day my mail was literally exploding because of dozens of crash reports happening every time a coroutine was fired (So every time the user opened the app). Main brands are Samsung, LG and 1+.

I install a signed release on my device. Open. Crash. (I do not use proguard, nor dexguard / minify)

Now, really perplexed, I run the debug build on my phone (Samsung Galaxy S6 edge With Custom rom LineageOS 16.0 Android 9) and I run it, crashes.

Next, I desperately clean the project, erase Gradle cache and Android Studio indexes, I reboot my whole system, rebuild everything, set the coroutine version to 1.3.2 and update the Fabric plugin to 1.31.1 (from 1.27.1). I deploy the updated debug version to my device and it works, no error are reported by the console. I rebuild a signed release version and i deploy it to the device, and it works again.

I don’t know if it’s a gradle-cache related bug, a coroutine internal error or something else, I just wanted to share my experience and maybe help out if someone else faces my same issue.

Thank you for your time 😃

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
fegan104commented, Feb 5, 2020

@patjackson52 Ran into this one using kotlin 1.3.60, coroutines 1.3.3 , and lifecycle-ktx 2.2.0 Only happens on release builds, debug builds without minify enables run with no issues. Invalidate caches restarting did nothing for me.

2reactions
igorwojdacommented, Oct 25, 2019

My project is also complex, so hard to reproduce it on a small scale. 1.3.2 was working fine for a while, but now I have a crash all the time.

Downgrading 1.3.2 -> 1.3.0 solves the issue for me, but I also notices that running AS invalidate cache and restart makes 1.3.2 working perfectly again which lead me to conclusion that this is AS bug indeed.

Gradle: 5.6.2 AGP: 3.5.1 Build tools: 29.0.0 Kotlin: 1.3.50

Android Studio 3.5.1 Build #AI-191.8026.42.35.5900203, built on September 25, 2019 JRE: 1.8.0_202-release-1483-b49-5587405 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.15

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module with Main dispatcher is missing - Stack Overflow
It is NOT an Android project, but a plain Kotlin console project (the one that prints "hello world" in the command prompt), and...
Read more >
Kotlin Coroutines in Android — Unit Test - Medium
MainCoroutineRule helps us write the unit tests faster and avoid to rewrite the same code in every unit test. 4. Inject Dispatcher. We...
Read more >
Introducing kotlinx.coroutines 1.6.0 | The Kotlin Blog
A new API and multiplatform support for kotlinx-coroutines-test · Support for the new Kotlin/Native memory manager · Dispatcher views API.
Read more >
runtime NPE in Kotlin Coroutine Dispatcher - Issue Tracker
IllegalStateException : Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android'
Read more >
[ Kotlin - error ] Module with the Main dispatcher is missing
dependencies { . . implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2" }. - 코루틴 안드로이드 1.3.1 -> 1.3.2 로 변경하니 ...
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