JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.99k stars 1.16k forks source link

M4 issue: delay(Duration) throws an error #736

Closed ypujante closed 3 years ago

ypujante commented 3 years ago

After upgrading to M4 / 0.4.0 (from M3 0.3.0), the following code fails:

    Window(title = "Test") {
      LaunchedEffect(Unit) {
        delay(Duration.seconds(1))
        println("after delay")
      }
      Text("Hello world")
    }

with the following error

Caused by: java.lang.NoSuchMethodError: kotlinx/coroutines/DelayKt.delay-p9JZ4hM(JLkotlin/coroutines/Continuation;)Ljava/lang/Object; (loaded from file:/Volumes/Vault/Caches/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core-jvm/1.4.3/1051e11eb789ed1df93412bebe0f06e9d29160e4/kotlinx-coroutines-core-jvm-1.4.3.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@a495ce4a) called from class MainKt$main$2$1$1 (loaded from ... by jdk.internal.loader.ClassLoaders$AppClassLoader@a495ce4a).

Note that it works with delay(1000)

olonho commented 3 years ago

Interestingly, it fails with code like that, if Compose plugin is applied:


@ExperimentalTime
fun main() {
    runBlocking {
        launch {
            repeat(1000) { i ->
                println("job: I'm sleeping $i ...")
                delay(Duration.seconds(1))
            }
        }
    }
}``` 
olonho commented 3 years ago

Seems depends on version of kotlinx-coroutines-core. Fails with 1.4.x, and works with 1.5.0. And Compose uses 1.4.3.

olonho commented 3 years ago

https://android-review.googlesource.com/c/platform/frameworks/support/+/1717755 promotes Compose to 1.5.0.

olonho commented 3 years ago

@ypujante please try

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")
    implementation(compose.desktop.currentOs)
}

in your build.gradle.kts.

ypujante commented 3 years ago

I confirm that it works with this change. Another workaround is to do Duration.seconds(1).inWholeMilliseconds which does not introduce a dependency on a different version of couroutines.

hfhbd commented 3 years ago

https://github.com/Kotlin/kotlinx.coroutines/issues/2649

akurasov commented 3 years ago

Seems it is fixed. Reopen if not.

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.