Kotlin / kotlinx.coroutines

Library support for Kotlin coroutines
Apache License 2.0
13.08k stars 1.85k forks source link

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

Closed cioccarellia closed 4 years ago

cioccarellia commented 5 years ago

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 :)

cioccarellia commented 5 years ago

By the way, here i let you the original logcat and my build files. Hope it helps

Logcat

E/CrashlyticsCore: Failed to execute task.
    java.util.concurrent.TimeoutException
        at java.util.concurrent.FutureTask.get(FutureTask.java:206)
        at com.crashlytics.android.core.CrashlyticsBackgroundWorker.submitAndWait(CrashlyticsBackgroundWorker.java:41)
        at com.crashlytics.android.core.CrashlyticsController.handleUncaughtException(CrashlyticsController.java:321)
        at com.crashlytics.android.core.CrashlyticsController$6.onUncaughtException(CrashlyticsController.java:301)
        at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:42)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
        at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.handleCoroutineExceptionImpl(CoroutineExceptionHandlerImpl.kt:40)
        at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(CoroutineExceptionHandler.kt:33)
        at kotlinx.coroutines.StandaloneCoroutine.handleJobException(Builders.common.kt:184)
        at kotlinx.coroutines.JobSupport.tryFinalizeFinishingState(JobSupport.kt:226)
        at kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath(JobSupport.kt:849)
        at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:811)
        at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:787)
        at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:111)
        at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:52)
        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)
        at com.andreacioccarelli.turbounfollow.App.onCreate(App.kt:47)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5920)
        at android.app.ActivityThread.access$1100(ActivityThread.java:200)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6718)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
? 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)
        at com.andreacioccarelli.turbounfollow.App.onCreate(App.kt:47)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5920)
        at android.app.ActivityThread.access$1100(ActivityThread.java:200)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6718)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
? W/ActivityManager:   Force finishing activity com.andreacioccarelli.turbounfollow/.activities.main.MainActivity
? I/ActivityManager: Showing crash dialog for package com.andreacioccarelli.turbounfollow u0

[App Module] build.gradle.kts

@file:Suppress("SpellCheckingInspection")

import org.jetbrains.kotlin.config.KotlinCompilerVersion

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}

plugins {
    id("com.android.application")
    id("kotlin-android")
    id("kotlin-android-extensions")
    id("io.fabric")
    id("com.github.konifar.gradle.unused-resources-remover")
    id("kotlin-kapt")
}

apply {
    plugin("kotlin-android")
}

android {
    compileSdkVersion(29)
    defaultConfig {
        applicationId = "com.andreacioccarelli.turbounfollow"
        buildToolsVersion = "28.0.3"
        multiDexEnabled = true
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true

        minSdkVersion(21)
        targetSdkVersion(29)

        versionCode = 71
        versionName = "2.0.0-beta"

        buildConfigField("boolean", "isTestingVersion", "true")
        buildConfigField("boolean", "isUIMockupVersion", "false")
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    buildTypes {
        named("release") {
            isMinifyEnabled = false
            isShrinkResources = false
            setProguardFiles(
                listOf(
                    getDefaultProguardFile("proguard-android.txt")
                )
            )
        }
    }

    sourceSets {
        getByName("main").java.srcDirs("src/main/kotlin")
        getByName("test").java.srcDirs("src/test/kotlin")
    }

    packagingOptions {
        exclude("META-INF/DEPENDENCIES")
        exclude("META-INF/LICENSE")
        exclude("META-INF/LICENSE.txt")
        exclude("META-INF/license.txt")
        exclude("META-INF/NOTICE")
        exclude("META-INF/NOTICE.txt")
        exclude("META-INF/notice.txt")
        exclude("META-INF/ASL2.0")
        exclude("META-INF/library_release.kotlin_module")
        exclude("META-INF/atomicfu.kotlin_module")
        exclude("META-INF/core_release.kotlin_module")
        exclude("META-INF/library-core_release.kotlin_module")
    }

    lintOptions {
        // checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        setAbortOnError(false)
    }
}

dependencies {
    implementation(
        fileTree(
            mapOf(
                "dir" to "libs",
                "include" to listOf("*.jar")
            )
        )
    )

    // 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")

    // AndroidX
    implementation("androidx.cardview:cardview:1.0.0")
    implementation("androidx.browser:browser:1.0.0")
    implementation("androidx.preference:preference:1.1.0")
    implementation("androidx.legacy:legacy-support-v4:1.0.0")
    implementation("androidx.vectordrawable:vectordrawable-animated:1.1.0")
    implementation("androidx.media:media:1.1.0")
    implementation("androidx.appcompat:appcompat:1.1.0")
    implementation("androidx.multidex:multidex:2.0.1")
    implementation("androidx.constraintlayout:constraintlayout:1.1.3")
    implementation("androidx.lifecycle:lifecycle-extensions:2.1.0")

    // Room
    val roomVersion = "2.1.0"
    implementation("androidx.room:room-runtime:$roomVersion")
    implementation("androidx.room:room-ktx:$roomVersion")
    kapt("androidx.room:room-compiler:$roomVersion")

    // Firebase
    implementation("com.google.android.gms:play-services-base:17.1.0")
    implementation("com.google.firebase:firebase-core:17.2.0")
    implementation("com.google.firebase:firebase-ads:18.2.0")
    implementation("com.google.firebase:firebase-analytics:17.2.0")
    implementation("com.google.firebase:firebase-config:19.0.2")
    implementation("com.crashlytics.sdk.android:crashlytics:2.10.1")
    implementation("com.google.android.gms:play-services-gcm:17.0.0")

    // Client
    val gson = "2.8.5"
    val okhttp = "4.2.0"

    implementation("com.google.code.gson:gson:$gson")
    implementation("com.squareup.okhttp3:okhttp:$okhttp")

    // Libraries
    val coil = "0.7.0"
    val job = "1.3.0-rc1"
    val karn = "1.3.0"

    implementation("io.coil-kt:coil:$coil")
    implementation("com.evernote:android-job:$job")
    implementation("com.anjlab.android.iab.v3:library:1.1.0")
    implementation("com.mikepenz:aboutlibraries:7.0.3")
    implementation("com.afollestad:assent:2.3.1")
    implementation("io.karn:notify:$karn")
    implementation("com.afollestad:recyclical:1.0.1")
    implementation("com.github.AndreaCioccarelli:CryptoPrefs:1.3.2.5")
    implementation("com.github.AndreaCioccarelli:LogKit:1.2.0")
    implementation("com.github.AndreaCioccarelli:AppIntro:308421725c")
    implementation("com.github.AndreaCioccarelli:BillingProtector:1.3.2")
    implementation("com.github.yandextaxitech:binaryprefs:1.0.1")
    implementation("commons-codec:commons-codec:1.13")

    // XML Views
    implementation("com.aurelhubert:ahbottomnavigation:2.3.4")
    implementation("com.budiyev.android:circular-progress-bar:1.2.2")
    implementation("com.robinhood.spark:spark:1.2.0")
    implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
    implementation("de.hdodenhof:circleimageview:3.0.1")
    implementation("com.github.chrisbanes:PhotoView:2.3.0")
    implementation("com.github.rubygarage:emotion-rating-view:v1.0.1")
    implementation("com.kevalpatel2106:ruler-picker:1.1")
    implementation("com.robertlevonyan.view:CustomFloatingActionButton:3.0.0")

    // UI
    val materialDialogs = "3.1.1"
    val popupMenu = "4.0.0"
    val toasty = "1.4.2"

    implementation("com.afollestad.material-dialogs:core:$materialDialogs")
    implementation("com.afollestad.material-dialogs:input:$materialDialogs")
    implementation("com.afollestad.material-dialogs:bottomsheets:$materialDialogs")
    implementation("com.github.zawadz88.materialpopupmenu:material-popup-menu:$popupMenu")
    implementation("com.github.GrenderG:Toasty:$toasty")
    implementation("com.github.daniel-stoneuk:material-about-library:2.4.2")
    implementation("io.github.inflationx:calligraphy3:3.1.1")
    implementation("io.github.inflationx:viewpump:2.0.3")

}

apply(plugin = "com.google.gms.google-services")
repositories {
    mavenCentral()
}

[Global] build.gradle.kts

@file:Suppress("LocalVariableName")

buildscript {
    val kotlin_version = "1.3.50"

    repositories {
        google()
        maven("https://jitpack.io")
        maven("https://maven.fabric.io/public")
        maven("https://plugins.gradle.org/m2/")
        jcenter()
    }

    dependencies {
        classpath("com.android.tools.build:gradle:3.5.1")
        classpath(kotlin("gradle-plugin", version = kotlin_version))

        classpath("com.google.gms:google-services:4.3.2")
        classpath("io.fabric.tools:gradle:1.31.1")
        classpath("gradle.plugin.com.github.konifar.gradle:plugin:0.3.3")
    }
}

allprojects {
    repositories {
        google()
        maven("https://jitpack.io")
        jcenter()
    }
}

tasks {
    val clean by registering(Delete::class) {
        delete(buildDir)
    }
}
bohsen commented 5 years ago

Duplicate of #1557

qwwdfsad commented 5 years ago

Thanks for the report, it indeed looks like #1557

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.

Could you please clarify whether the same issue is reproducible on the emulator?

cioccarellia commented 5 years ago

Right now I don't have anymore the possibility of reproducing that issue, because it has somehow disappeared. I thunk that cleaning caches and restarting did the trick. Nonetheless, I honestly think you have very little information to track this down, it may be an android compiler bug, an Android Studio bug, a Gradle caching bug or god knows what else.

I will dig deeper into that, I'll add my OS details. My PC: MacBook Pro Mid-2009 My PC CPU: 2,8 GHz Intel Core 2 Duo My OS: OS X El Capitan 10.11.6 (15G22010) 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 Mac OS X 10.11.6

Project Gradle Version: 5.6.1 Gradle Properties:

org.gradle.jvmargs=-Xmx2048m
kotlin.code.style=official
android.enableD8.desugaring=true
android.enableD8=true
# android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
org.gradle.parallel=true
kapt.incremental.apt=true
bohsen commented 5 years ago

Nonetheless, I honestly think you have very little information to track this down, it may be an android compiler-related bug, an Android Studio bug, a Gradle caching flaw or god knows what else.

So true. This could just as likely be related to android arch lifecycle-extensions libraries, that has been through an extensive development the last couple of month after introducing coroutines.

Also the problem disappears out of the thin air after a gradle clean and a restart. No way to reproduce.

qwwdfsad commented 5 years ago

Thanks for the details. FYI we want to switch to a new Class.forName-based strategy on Android (#1572) because ServiceLoader proved to be unstable on various Android devices. Targeting 1.3.3

cioccarellia commented 5 years ago

Hope it will make this process more stable and reliable, but I'm not completely sure it's your fault, if it happens again I'll make sure to scan every possible detail

cioccarellia commented 5 years ago

No regressione detected, I really think it's Gradle/AS.

itboy87 commented 5 years ago

Rebuild Project and try again it worked for me.

igorwojda commented 5 years ago

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

recoverrelax commented 5 years ago

i have the same problem with 1.3.2. downgrade works (1.3.1). No other solution here works

cioccarellia commented 5 years ago

Have you tried clearing your local Gradle cached, Android Studio indexes and rebuilding everything?

On Wed, Oct 30, 2019, 12:53 PM recoverrelax notifications@github.com wrote:

i have the same problem with 1.3.2. downgrade works (1.3.1). No other solution here works

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Kotlin/kotlinx.coroutines/issues/1606?email_source=notifications&email_token=AFPRZJ6B2BJL2KSQV3XGAS3QRFYUZA5CNFSM4I7CG7QKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECT4GJY#issuecomment-547865383, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFPRZJ6D7MTMUYHIK3JRDXLQRFYUZANCNFSM4I7CG7QA .

igorwojda commented 5 years ago

Clearing the cache worked for me, but only for a while (build or two), but in my case problem always recurred quite quickly so downgrade was only reliable solution.

Pierry commented 5 years ago

In my case, all was work fine in dev build, but when I published my app, all sessions are crashing. I downgraded version to 1.1.1 (my last version on Google Play) and now everything is ok. (32k users with crash).

p-lr commented 5 years ago

Ran into the same issue. Invalidate cache and rebuilding the project worked using 1.3.2.

patjackson52 commented 4 years ago

Is this an issue with 1.3.3?

fegan104 commented 4 years ago

@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.

almakhanov commented 4 years ago

@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.

worked for me

fegan104 commented 4 years ago

@almakhanov Turns out I was using an outdated AGP version. Upgrading to the latest stable version fixed it for me 👍

aoben10 commented 4 years ago

@fegan104 Also seeing this issue. Which version of the AGP worked for you?

fegan104 commented 4 years ago

@aoben10 I'm using v5.4.1 but the latest stable version should also work

mingdong-recolor commented 4 years ago

Having had the issue all of sudden, works for me after done Invalidate Caches/Restart in Android Studio.

maplee commented 4 years ago

need keep kotlinx-coroutines-android perfect solution

-keep class kotlinx.coroutines.android.* {;}

hs-kdhillon commented 4 years ago

I am using 1.3.3 and still received this crash in crashlytics. I tried using both core and android dependencies, however, the issue still persists:

Fatal Exception: java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'
       at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.missing(MissingMainCoroutineDispatcher.java:88)
       at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.isDispatchNeeded(MissingMainCoroutineDispatcher.java:69)
       at kotlinx.coroutines.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuationKt.java:268)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(CancellableKt.java:26)
       at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.java:109)
       at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.java:158)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(BuildersKt__Builders_commonKt.java:54)
       at kotlinx.coroutines.BuildersKt.runBlocking(BuildersKt.java:1)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(BuildersKt__Builders_commonKt.java:47)
       at kotlinx.coroutines.BuildersKt.runBlocking(BuildersKt.java:1)
       at com.homestars.homestarsforbusiness.reviews.details.ReviewDetailViewModel.onCreate(ReviewDetailViewModel.java:80)
       at biz.homestars.homestarsforbusiness.base.viewmodel.ViewModelHelper.onCreate(ViewModelHelper.java:62)
       at biz.homestars.homestarsforbusiness.base.viewmodel.base.ViewModelBaseFragment.onCreate(ViewModelBaseFragment.java:28)
       at biz.homestars.homestarsforbusiness.base.HSFragment.onCreate(HSFragment.java:41)
       at com.homestars.homestarsforbusiness.reviews.details.ReviewDetailFragment.onCreate(ReviewDetailFragment.java:86)
       at androidx.fragment.app.Fragment.performCreate(Fragment.java:2586)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:838)
       at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1197)
       at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1080)
       at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:119)
       at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1866)
       at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
       at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
       at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2663)
       at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManagerImpl.java:2613)
       at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:246)
       at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:542)
       at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201)
       at biz.homestars.homestarsforbusiness.base.HSActivity.onStart(HSActivity.java:90)
       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1433)
       at android.app.Activity.performStart(Activity.java:7978)
       at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3472)
       at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
       at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:7811)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
fegan104 commented 4 years ago

@hs-kdhillon What's your AGP version?

hs-kdhillon commented 4 years ago

@hs-kdhillon What's your AGP version?

I am using 3.2.0 @fegan104

fegan104 commented 4 years ago

@hs-kdhillon What's your AGP version?

I am using 3.2.0 @fegan104

Try updating to the latest version

beigirad commented 4 years ago

I have this issue on 1.3.8 when I enabling minify

    java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'
fegan104 commented 4 years ago

@beigirad Try updating your AGP

makingthematrix commented 4 years ago

Just an additional hint if anyone tries the solutions from above and they didn't work.

For me, a rule in proguard-rules.txt did the job:

-keep class kotlinx.coroutines.android.** {*;}

My setup is kotlinx-coroutines-android:1.3.9, no kotlinx-coroutines-core (I removed it as it turned out to be unnecessary), Kotlin 1.3.72, and Gradle 3.2.1.

camelCaseD commented 3 years ago

Ran into this issue earlier this week with the missing dispatcher exception. After attempting all the suggestions here to resolve it and none of them working for me. I made the discovery that the APKs I was working on are release builds signed with the old jar signer. For whatever reason when running the jar signed APKs on a device running Android Marshmallow I would get the exception thrown. But when I signed them with the newer apk signer the crash would no longer happen.

So for anyone that comes across this and are still getting this exception even after updating AGP I recommend looking into seeing if you have a build script somewhere signing the APK with jar signer.

onurkoncaoglu commented 5 months ago

I also ran this issue and I realized that one of my packaging options leads this error:

packagingOptions {
    pickFirst  '**'
}

If you face with this error you can also check your app build.gradle configuration, somehow this packingOptions broke jar signer options