撰写崩溃并出现错误“kotlinx.coroutines.channels.Channel”

时间:2021-07-02 06:09:08

标签: android kotlin-coroutines android-jetpack android-jetpack-compose

Compose app crash with error:

$ javac $cur_file # modified so the Main class is not public
$ java $cur_class # which was obtained from parsing $cur_file

我的应用程序 gradle 文件:

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)

2 个答案:

答案 0 :(得分:0)

Core 当前的稳定版本是 1.6.0。会是这样吗?

替换:

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

与:

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

答案 1 :(得分:0)

我遇到了同样的问题。 我通过更新 Kotlin 协程修复了它。因为 'kotlinx.coroutines.channels.Channel' 是 Kotlin Coroutines 中的一个类。

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