cashapp / molecule

Build a StateFlow stream using Jetpack Compose
https://cashapp.github.io/molecule/docs/1.x/
Apache License 2.0
1.9k stars 82 forks source link

Crash when embedding molecule into an XCFramework and running it on an iOS app #547

Open danielPerez97 opened 1 day ago

danielPerez97 commented 1 day ago

Hello. I'm not entirely sure this is an error with Molecule itself or I am just setting up the Gradle code for building the XCFramework poorly. Any help would be appreciated. I am building a Kotlin Multiplatform module that uses Molecule for iOS and trying to run it mixed with Swift code.

Here is the error in XCode:

Thread 3: EXC_BAD_ACCESS (code=1, address=0x0)
    0x106a7efe4 <+752>:  bl     0x106a7f97c               ; _6d6f6c6563756c653a6d6f6c6563756c652d72756e74696d652f55736572732f72756e6e65722f776f726b2f6d6f6c6563756c652f6d6f6c6563756c652f6d6f6c6563756c652d72756e74696d652f7372632f71756172747a436f72654d61696e2f6b6f746c696e2f6170702f636173682f6d6f6c6563756c652f446973706c61794c696e6b436c6f636b2e6b74_knbridge18
->  0x106a7efe8 <+756>:  b      0x106a7efec               ; <+760> at DisplayLinkClock.kt:36:93
    0x106a7efec <+760>:  bl     0x105952070               ; Kotlin_mm_switchThreadStateRunnable_debug
    0x106a7eff0 <+764>:  b      0x106a7eff4               ; <+768> at DisplayLinkClock.kt

I've put the code in this repo. Running the Android app works perfectly using the :Frontend module, but just not having the same luck on iOS. https://github.com/danielPerez97/Pourover/

Steps to Recreate: 1) Run gradlew Frontend:assembleFourSixFrontendLibDebugXCFramework: 2) Copy the XCFramework at Frontend/build/XCFrameworks/debug/FourSixFrontendLib.xcframework into iOS/Pourover 3) Run the iOS app on a simulator

Like I said I'm not sure this is a Molecule issue, and feel free to close it if it isn't.

JakeWharton commented 23 hours ago

We also have a display link clock in Redwood, so it's possible we need to port over some improvements from it.

danielPerez97 commented 22 hours ago

Hmm, I may try to rip the DisplayLinkClock code from Redwood, and rebuild Molecule locally with some includeBuild() magic then. Would this be the file to rip?

https://github.com/cashapp/redwood/blob/7773cd4b73c0f9b00e7459b8f54f61459b02eda6/redwood-compose/src/iosMain/kotlin/app/cash/redwood/compose/DisplayLinkClock.kt#L30

I'm completely new to getting a Kotlin Multiplatform library to run on iOS, if there's any way you know where I can get you better error messages I'd be happy to enable whatever I need to. I'm really unsure if this is even a Molecule issue.

Edit: It seems there is some redwood-specific stuff in the DisplayLInkClock. I'll just wait on an update, thanks for the help.

JakeWharton commented 22 hours ago

This is the one we use in production: https://github.com/cashapp/redwood/blob/trunk/redwood-treehouse-host/src/iosMain/kotlin/app/cash/redwood/treehouse/IosDisplayLinkClock.kt

It's not exactly the same setup as a "normal" FrameClock, but it drives an abstraction which is nearly identical.