David Everlöf
03/05/2025, 1:26 PMBradleycorn
03/05/2025, 5:16 PMDavid Everlöf
03/05/2025, 5:34 PMDavid Everlöf
03/05/2025, 5:34 PMDavid Everlöf
03/05/2025, 5:34 PMBradleycorn
03/05/2025, 5:50 PMBradleycorn
03/05/2025, 5:50 PMDavid Everlöf
03/05/2025, 5:50 PMBradleycorn
03/05/2025, 5:50 PMBradleycorn
03/05/2025, 5:51 PMDavid Everlöf
03/05/2025, 5:52 PMDavid Everlöf
03/05/2025, 5:52 PMBradleycorn
03/05/2025, 5:53 PMbut the problem is it's (AFAIK) impossible to get SwiftUI Previews working if the KMP module is statically linked.Correct! You can still use firebase, you just can't use CrashKiOS .. hang on let me find my other thread that talks about this
David Everlöf
03/05/2025, 5:54 PMDavid Everlöf
03/05/2025, 5:54 PMBradleycorn
03/05/2025, 5:54 PMDavid Everlöf
03/05/2025, 5:55 PMBradleycorn
03/05/2025, 5:55 PMBradleycorn
03/05/2025, 5:55 PMBradleycorn
03/05/2025, 5:56 PMBradleycorn
03/05/2025, 5:56 PMDavid Everlöf
03/05/2025, 5:57 PMDavid Everlöf
03/05/2025, 5:57 PMBradleycorn
03/05/2025, 5:57 PMkpgalligan
03/05/2025, 6:02 PMkpgalligan
03/05/2025, 6:02 PMkpgalligan
03/05/2025, 6:13 PMMy problem is that I get crashes directly when opening the app (only when running release builds from Apple, such as testflight)This is a known issue. It seems that somewhere in that pipeline, necessary symbols are being stripped. We've iterated on trying to solve it, but it's really deep-native linking stuff, and not easy to deal with. The general problem is that KMP and native 3rd party integration is a huge pain. It has been a serious KMP issue, and will very much impact library dev for CMP. Solving it is not trivial, but this problem really needs a more general solution than the "fixes" each library tries to use.
We've had our KMP module static for a while, but the problem is it's (AFAIK) impossible to get SwiftUI Previews working if the KMP module is statically linked.This specific problem has a reasonable workaround. Make debug builds dynamic and release builds static. How you do that depends on how you hand off to iOS devs. I took a dive into how NSExceptionKt avoids the linking issue, and assuming I'm correct, nothing in Kotlin directly calls the code generated by cinterop. It's a clever workaround, but that means you can't do things like log breadcrumbs, add data, send handled exceptions (directly), etc. I think. Assuming I'm correct, that won't really work for CrashKiOS, unless we took out all of those features. The current problem specific to Crashlytics is, I believe, the result of a change we made to get around the linking issues. Rather than use cinterop to talk to Crashlytics, we're dynamically calling the Objc methods. That works, unless something in the release pipeline removes something it doesn't think is being used but actually is. That's my current understanding of the situation (I didn't work on that specifically). To update CrashKiOS, we need a refactor that doesn't try to avoid cinterop in the same way, and I want to apply it to both Crashlytics and Bugsnag, because the linking situation is a mess in general. Early versions of CrashKiOS actually required copy/pasting Swift code, which is ugly, but simple. Other options include using CocoaPods to link Crashlytics, but using SPM externally. This is what Sentry does, which works, but generally gets a 🤮 response. I have another clever idea, but I'm kind of tired of clever ideas, so I'm not sure we'll do that one 🙂
kpgalligan
03/05/2025, 6:17 PMDavid Everlöf
03/05/2025, 6:53 PM./gradlew watch:embedAndSignAppleFrameworkForXcode
I guess your suggestion the is to use XCFramework for releases and embedAndSignAppleFrameworkForXcode
for debug?kpgalligan
03/05/2025, 6:59 PMembedAndSignAppleFrameworkForXcode
. What the CocoaPods plugin used to do is pass env vars from Xcode to tell Kotlin what architecture and variant to use. I would assume embedAndSignAppleFrameworkForXcode
does something similar, or it would just build "everything" every time, and that's clearly not how it works. I would maybe try adding code to Gradle to print out all env vars, then do a debug build and a release build. Then you could flip static/dynamic based on that.kpgalligan
03/05/2025, 6:59 PMDavid Everlöf
03/05/2025, 7:06 PMkpgalligan
03/05/2025, 7:14 PMembedAndSignAppleFrameworkForXcode
. I'm just guessing it also uses env vars in some way to communicate to the Kotlin compiler, so you could maybe use those to flip the static flag.David Everlöf
03/05/2025, 7:15 PMembedAndSignAppleFrameworkForXcode
from the terminal for example, due to just that!David Everlöf
03/05/2025, 7:15 PMkpgalligan
03/05/2025, 7:18 PMembedAndSignAppleFrameworkForXcode
, it's (probably) setting something like BUILD_VARIANT=DEBUG
as an env var. Once you figure out the name and values, you can just do an if
in gradle to change the static flag. When you're doing dev, that won't change from build to build, so it shouldn't blow up your config time.kpgalligan
03/05/2025, 7:18 PMso it shouldn't blow up your config time.Key word is "shouldn't"
David Everlöf
03/05/2025, 7:20 PMKOTLIN_FRAMEWORK_BUILD_TYPE
kpgalligan
03/05/2025, 7:21 PMDavid Everlöf
03/05/2025, 7:22 PMBradleycorn
03/05/2025, 7:31 PMMake debug builds dynamic and release builds static.I considered that approach, but the QA in me worries about that introducing defects that don't get caught early enough in development. I'm sure we've all ran into a similar issue in Android in our lives, where code works fine in debug builds, but release builds crash because Proguard is stripping some class out. Feels like we could run into similar situations in ios if we use a static/dynamic switch?
Bradleycorn
03/05/2025, 7:34 PMkpgalligan
03/05/2025, 7:38 PMFeels like we could run into similar situations in ios if we use a static/dynamic switch?Well, it's one of those "pick your poison" kind of situations. I can't say you absolutely won't, but I can say there are other things that can (and have) happened. For example, I've had issues simply using release vs debug builds. Forget static vs dynamic. In theory, issues between static and dynamic would be reasonably fatal, which is good because you'd know immediately. Also, assuming you have QA builds, or at least some kind of dogfood builds, those would all be built with release binary, and/or you could force them to use a static build, so it's a risk that could be minimized to virtually zero.
kpgalligan
03/05/2025, 7:38 PMit's a risk that could be minimized to virtually zero.That is the risk of publishing anything with an issue.
Bradleycorn
03/05/2025, 7:39 PMkpgalligan
03/05/2025, 7:39 PMkpgalligan
03/05/2025, 7:39 PMBradleycorn
03/05/2025, 7:40 PMkpgalligan
03/05/2025, 7:41 PMkpgalligan
03/05/2025, 7:41 PMBradleycorn
03/05/2025, 7:44 PMkpgalligan
03/05/2025, 7:52 PMDavid Everlöf
03/06/2025, 11:54 AM.framework
when building debug
, but not for release
.kpgalligan
03/06/2025, 3:19 PM