Compose crash with error "kotlinx.coroutines.channels.Channel"

Viewed 920

Compose app crash with error:

java.lang.NoSuchMethodError: No interface method trySend-JP2dKIU(Ljava/lang/Object;)Ljava/lang/Object; in class Lkotlinx/coroutines/channels/Channel; or its super classes (declaration of 'kotlinx.coroutines.channels.Channel' appears in /data/app/~~x0AHNhyBSh0nzc6B-ZQp6g==/com.test.app-h8KTWE9gDnxiOcVLPrnmkA==/base.apk!classes28.dex)
                at androidx.compose.ui.platform.GlobalSnapshotManager$ensureStarted$2.invoke(GlobalSnapshotManager.android.kt:50)
                at androidx.compose.ui.platform.GlobalSnapshotManager$ensureStarted$2.invoke(GlobalSnapshotManager.android.kt:49)
                at androidx.compose.runtime.snapshots.SnapshotKt.notifyWrite(Snapshot.kt:1651)
                at androidx.compose.runtime.SnapshotMutableStateImpl.setValue(SnapshotState.kt:916)
                at androidx.compose.ui.platform.AndroidComposeView.setViewTreeOwners(AndroidComposeView.android.kt:1260)
                at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:813)
                at android.view.View.dispatchAttachedToWindow(View.java:20483)

My app gradle file:

dependencies {
    implementation(project(":mpp-library"))

    implementation("androidx.core:core-ktx:1.5.0")
    implementation("com.google.android.material:material:1.3.0")
    implementation("androidx.appcompat:appcompat:1.3.0")
    implementation("androidx.constraintlayout:constraintlayout:2.0.4")

    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")

    val compose_version = "1.0.0-rc01"
    implementation("androidx.compose.ui:ui:${compose_version}")
    implementation("androidx.compose.foundation:foundation:${compose_version}")
    implementation("androidx.compose.material:material:${compose_version}")
    implementation("androidx.compose.material:material-icons-core:${compose_version}")
    implementation("androidx.compose.material:material-icons-extended:${compose_version}")
    implementation("androidx.compose.ui:ui-tooling:$compose_version")
}

android {
    compileSdkVersion(30)
    defaultConfig {
        applicationId = "com.test.myapp"
        minSdkVersion(21)
        targetSdkVersion(30)
        versionCode = 1
        versionName = "1.0"
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }

    packagingOptions {
        exclude("META-INF/*.kotlin_module")
    }

    composeOptions {
        kotlinCompilerExtensionVersion = compose_version
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    buildFeatures {
        compose = true
        dataBinding = true
        viewBinding = true
    }

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

I had the same problem. I fixed it by updating Kotlin Coroutines. Because 'kotlinx.coroutines.channels.Channel' is a class in Kotlin Coroutines.

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")

The current stable release of Core is 1.6.0. Could be that?

Replace:

implementation("androidx.core:core-ktx:1.5.0")

with:

implementation("androidx.core:core-ktx:1.6.0")
Related