Closed pablichjenkov closed 1 month ago
Forgot to mention, if I try a different version of compose compiler, lets say, 1.3.0-rc01 or 1.3.0-beta04-dev903, then I get the following error:
> Task :compileKotlinJs FAILED
e: Could not find "org.jetbrains.kotlinx:kotlinx-coroutines-core"
I am using version 1.6.3 of the kotlinx-coroutines in my commonMain
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3")
Just to add more details: even more simple code fails too:
@Composable
fun TestRememberObject() {
val obj = remember { object {} }
}
As a very rough workaround for now, you may try to create an instance you need to remember
in a separate function and call it within remember {}:
fun createObject(addYourParamsHere...): BackPressedCallback {
return object : BackPressedCallback {
override fun onBackPressed() {
TODO("Not yet implemented")
}
}
}
@Composable
fun TestRememberObject() {
val obj = remember { createObject() }
}
Btw, I noticed the weird behaviour: It compiles normally on a second attempt (in my project though, I haven't tested your example yet). But when I change something in the code, it fails again, but compiles on a second attempt again. Did you notice this?
Work around works! Now in regards to the weird behavior you observe, I don't see the same. In my case is pretty consistent, compiler fails all the time. I have tried with the following version combinations too:
compose.version=1.2.2 kotlin.version=1.7.20
compose.version=1.2.1 kotlin.version=1.7.20
compose.version=1.3.0-alpha01-dev827 kotlin.version=1.7.10
Same behavior all combinations above.
No good fix yet, but found another thing that helps to workaround:
val backCallback = remember<BackPressedCallback > { ... }
// or
val backCallback: BackPressedCallback = remember { ... }
Thanks for that suggestion @eymar - looks like being explicit about the type when working with anonymous objects is what was needed in my similar case.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Using code similar to the one shown below will cause the kotlin compiler the fail when targeting JS(IR).
Exception:
w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions
FAILURE: Build failed with an exception.
Can see the code in question in the following file: https://github.com/pablichjenkov/component-toolkit/blob/3816574c0b67fd4fc8dd749aab4af1b4f9362451/component-toolkit/src/commonMain/kotlin/com/pablichj/templato/component/core/backpress/BackPressHandler.kt#L23
Steps to reproduce
1- git clone git@github.com:pablichjenkov/uistate3.git 2- git checkout kotlin-js-compilation-fails 3- From the project root directory execute the following command: ./gradlew clean jsBrowserDevelopmentRun
gradle.properties: