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.17k stars 1.11k forks source link

Unable to link downstream project consuming Kotlin/Native-built runtime #2342

Closed JakeWharton closed 1 year ago

JakeWharton commented 1 year ago
> Task :molecule-runtime:linkDebugTestIosSimulatorArm64 FAILED
e: Compilation failed: Failed to compute the detailed error message. See the root cause exception.

Shortly: The required symbol androidx.compose.runtime/remember|-4100818973694024771[0] is missing in the module or module dependencies. This could happen if the required dependency is missing in the project. Or if there is a dependency that has a different version (without the required symbol) in the project than the version (with the required symbol) that the module was initially compiled with.

I have kotlin.native.cacheKind=none set in the project's gradle.properties but it still does not compile.

Repro on this branch https://github.com/cashapp/molecule/tree/jw/link-thing/2022-09-21 running ./gradlew -p molecule :m-r:check.

dima-avdeev-jb commented 1 year ago

I will research

dima-avdeev-jb commented 1 year ago

I reproduced this problem with iosSimulatorArm64Test task. I will continue try to fix it.

But also, for now, you may use only jvm tests: ./gradlew -p molecule :m-r:jvmTest

DjakaTechnology commented 1 year ago

I can reproduce this, also happens when building to an iOS app target not just testing only. I can't use compose runtime in shared module because of this.

dima-avdeev-jb commented 1 year ago

I can reproduce this, also happens when building to an iOS app target not just testing only. I can't use compose runtime in shared module because of this.

Thanks! I will research your sample

eymar commented 1 year ago

Just noticed the same error in another project. In my case the compose compiler was not applied for k/native targets. In molecule runtime I see no compose gradle plugin applied (it applies the compiler plugin). Does compose plugin get applied for other targets in molecule runtime (and where is it configured)?

UPD: beside applying the compiler plugin, ComposeGradlePlugin also adds compiler options for k/js - https://github.com/JetBrains/compose-jb/blob/3996233b032772a5afb8ceceafc4affae793e480/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerKotlinSupportPlugin.kt#L67

So I guess, k/js is probably not working too in molecule:runtime?

cc: @JakeWharton

JakeWharton commented 1 year ago

You are correct we are not specifying the JS option correctly. Molecule's multiplatform entrance is a little more rash than Redwood where we did things a bit more carefully. That being said, we cannot use your Compose plugin because it assumes things about the JS target (the presence of a web extension) that doesn't work in the general case.

In Redwood we have a proper subproject plugin which applies the Compose compiler plugin and configures the JS build correctly: https://github.com/cashapp/redwood/blob/3956a7883950951f38e5d0c442d63b32cdfc955f/build-support/src/main/kotlin/app/cash/redwood/buildsupport/ComposePlugin.kt. I will do the same in Molecule here shortly.

JakeWharton commented 1 year ago

This issue has resolved itself, but I'm not quite sure why. I upgraded to Kotlin 1.7.20 and JB Compose 1.2.1 (and compiler 1.3.2.1) along with adding the cacheKind=none option and it started to succeed. We also had other build changes such as removing the use of includeBuild across multiplatform projects which is known to not work well, but that shouldn't have affected the behavior.

(Separately I fixed our Gradle plugin to use JS decoys for downstream projects as well as using JS decoys for our own build. Thanks!)

Going to preemptively close and hope it's not an issue in the future!

saket commented 1 year ago

I was also able to fix this specific issue by upgrading to Kotlin 1.7.20, but ended up running into another wall:

e: Compilation failed: Unbound symbols not allowed

Unbound public symbol IrSimpleFunctionPublicSymbolImpl: me.saket.teleport.ui/Presenter.present|-8951064700938915987[0]

 * Source files:
 * Compiler version info: Konan: 1.7.20 / Kotlin: 1.7.20
 * Output kind: FRAMEWORK

e: java.lang.AssertionError: Unbound symbols not allowed

@JakeWharton Do you still have your jw/link-thing/2022-09-21 branch around? I'd like to compare my setup with yours.

hfhbd commented 1 year ago

@saket Did you add kotlin.native.cacheKind=none? I got the same error and this resolved it.

saket commented 1 year ago

Yea I already had kotlin.native.cacheKind=none in my gradle.properties so I believe I'm running into something else. Do you have a public project that I can take a look at?

hfhbd commented 1 year ago

I have a work-in-progress pr to include molecule into my playground app: https://github.com/hfhbd/ComposeTodo/pull/665/files

I had to add the molecule runtime manually though because I also use the compose plugin: https://github.com/cashapp/molecule/issues/134

dima-avdeev-jb commented 1 year ago

@saket Can you please try version 1.3.0-alpha01-dev849 with kotlin.native.cacheKind=none

saket commented 1 year ago

Sure, where are your alpha builds hosted on? I couldn't find any information in your readme or releases page.

saket commented 1 year ago

@hfhbd going through this, thank you!

dima-avdeev-jb commented 1 year ago

@saket You need set repository here: https://github.com/JetBrains/compose-jb/blob/master/experimental/examples/falling-balls-mpp/settings.gradle.kts#L6 and here: https://github.com/JetBrains/compose-jb/blob/master/experimental/examples/falling-balls-mpp/build.gradle.kts#L20

saket commented 1 year ago

Thanks! I'm seeing the same error with 1.3.0-alpha01-dev849.

mateuy-dev commented 1 year ago

@saket I had the same error in my case when using molecule. Its was caused due that composable functions couldn't be public in native (at least this is what I've read). I fixed it changing them to internal (an in my case only expose the flow created by the molecule launch)

dima-avdeev-jb commented 1 year ago

@saket Yeah, for now Composable functions for native can be only internal or private. We will fix it in the future.

Nailik commented 1 year ago

@saket Yeah, for now Composable functions for native can be only internal or private. We will fix it in the future.

Did this change or is this still valid?

eymar commented 1 year ago

@Nailik

for now Composable functions for native can be only internal or private. We will fix it in the future.

This part is fixed when using kotlin 1.8.20 and compose 1.4.0


kotlin.native.cacheKind=none - this parameter is still needed. The investigation has started by k/native team

Nailik commented 1 year ago

@Nailik

for now Composable functions for native can be only internal or private. We will fix it in the future.

This part is fixed when using kotlin 1.8.20 and compose 1.4.0

kotlin.native.cacheKind=none - this parameter is still needed. The investigation has started by k/native team

Unfortunately i still get error: Module "Rhasspy_Mobile:ui" has a reference to symbol androidx.compose.runtime/CompositionLocalProvider|1991010962478225151[0]. Neither the module itself nor its dependencies contain such declaration. with this project https://github.com/Nailik/rhasspy_mobile/tree/1454949c0d42b60ce48dc57ffb446e4061531522

Edit: This issue was caused because i forgot to add id("org.jetbrains.compose") in the plugins section