Anyone using KMM to create a published Android/iOS...
# multiplatform
b
Anyone using KMM to create a published Android/iOS Library (i.e. NOT an app)? I setup a KMM project (used Android Studio), and set it to use cocoapods to integrate the shared module into the ios app. I updated the generated ios app project (removed the app target, created a framework target, and copied over the build settings and such to use the cocoapods framework). Everything seems to work. I setup a build script to use xcodebuild to build device and simulator versions of the framework, and then combine them into an XCFramework. From there I setup a podspec, and publish (to a private podspec repo) the pod with the xcframework as the vendored_framework. I can then pull in my published ios pod into an app and use it. Everything seems ok. But then I go to run the app on a device, and it crashes with:
Library not loaded: shared.framework/shared
I think I understand why this happens, but I’m not sure how to fix it? A bit more info in the 🧵
c
If you’re building an internal library to be consumed by a separate iosApp project, you might look into KMMBridge
b
Thanks Casey. I have looked into KMMBridge, and it’s been extremely helpful in getting me to the point I am at. I may end up using it directly, but I also want to understand the how/why so I don’t just have to rely on a “black box” solution without really understanding what is going on.
the KMM project creates a Podfile for the ios app/framework and specifies:
pod 'sharedUiLogic', :path => '../sharedUiLogic'
That allows me to
import shared
in my Swift code, and use the shared module logic in my ios framework project. Great. Then I build the ios framework project into an xcframework, using xcodebuild. that works to produce the xcframework, and I can setup all the cocoapods/github stuff to publish a pod that will use the framework. But in doing so, it uses dynamic linking for the
sharedUiLogic
“pod”. So when I use my published framework in another app, it will compile OK, but at runtime … 💥. Basically
sharedUiLogic
is a dependency, and normally I’d setup my podspec to specify the dependency. But
sharedUiLogic
is obviously not a published pod, so you can’t really specify it as a dependency. I think I need to set
sharedUiLogic
up to be linked statically? Also, I’m not sure how to do that.
k
In the
cocoapods'
framework definition, you can set it to be static:
Copy code
kotlin {
    cocoapods {
        (...)
        framework {
            isStatic = true
        }
    }
}
104 Views