Android "Module with the Main dispatcher is missing" (v1.3.2)
See original GitHub issueHello, 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:
- Created 4 years ago
- Reactions:5
- Comments:31 (2 by maintainers)
@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.
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 ASinvalidate 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