kotlinx.coroutines: Android app with coroutines 0.30.1-eap13 crashes in runtime
java.lang.IllegalStateException: Module with Main dispatcher is missing. Add dependency with required Main dispatcher, e.g. 'kotlinx-coroutines-android'
at kotlinx.coroutines.Dispatchers.getMain(Dispatchers.kt:61)
kotlinx-coroutines-android is obviously added.
Version 0.30.0-eap13 works fine.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 8
- Comments: 22 (4 by maintainers)
Commits related to this issue
- Add workaround for androidx toolchain issues: try to load main dispatcher via Class.forName(..) if ServiceLoader failed to find dispatcher Fixes #657 — committed to Kotlin/kotlinx.coroutines by qwwdfsad 6 years ago
- Add workaround for androidx toolchain issues: try to load main dispat… (#709) Embed proguard rules to JAR resources to workaround Androidx issue with ServiceLoader, update documentation Fixes #657 — committed to Kotlin/kotlinx.coroutines by qwwdfsad 6 years ago
If an app is obfustacted with default proguard settings, it crashes in runtime. Here is sample project to reproduce an issue: https://www.dropbox.com/s/eay696h9qmxjl5e/sample.zip?dl=1 UPD: I’ve created PR #662 but it will not work, because
@Keepannotation is Android specific. Is the only way to add proguard rules?The same issue with
0.30.1in release build only (i. e. whenminifyEnabled trueis specified)Android Studio 3.1.2 Build #AI-173.4720617, built on April 14, 2018 JRE: 1.8.0_152-release-1024-b01 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.13.4
Didn’t work:
Worked:
Same issue here with 0.30.2.
The suggested proguard rules should be enough. I mean:
I was recently facing this issue and realised that it was my fault and nothing to do with the proguard rules. Basically, we were re-signing the apk and removing the META-INF folder in the process. So, for the ones that are still facing the issue, please make sure that you are not doing the same (re-signing your apk and removing the META-INF folder after the release build is done). If that’s the case, I would suggest you to generate an unsigned build and sign it afterwards.
Just for reference, I’m using the version 1.0.1.
implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1")Hope it helps.
We were having this crash without even using ProGuard 😅 As mentioned by @djrsousa, it’s because we were:
and replacing the META-INF folder in the process…
@bernaferrari then they need to be updated to
for kotlinx-coroutines-android
I did it in sample Android project and it works in both debug and release mode.
Again, works on my machine.
Please be cooperative. I’m willing to help you, but I can’t do anything with reports like “it doesn’t work”