Daniel
12/14/2024, 10:27 PMblakelee
12/14/2024, 11:40 PMkotlin {
listOf(
iosX64(),
iosArm64(),
).forEach {
it.binaries.framework {
baseName = "shared"
isStatic = true
linkerOpts("-framework") // I have "Network" added also but might be for something else
}
}
}
My Build Phases
tab looks similar but I only have FirebaseMessaging
. I have this for my package dependenciesblakelee
12/14/2024, 11:45 PMDaniel
12/14/2024, 11:45 PMkpgalligan
12/15/2024, 7:20 PMthe problem with static is that will add the packages to the iOS app binaries, hence the app for the end user will be biggerWhich packages? Static builds are generally smaller overall, unless there's something I'm not aware of here. In any case, you haven't added Firebase with cocoapods. That is required if you are building a dynamic framework, and/or if you want to run Kotlin tests with iOS targets. https://github.com/GitLiveApp/firebase-kotlin-sdk?tab=readme-ov-file#running-on-ios The Kotlin dependencies only include cinterop for Firebase. They do not link to Firebase binaries. It is a common problem when including 3rd party libraries on native platforms. I gave a talk about these topics a couple years ago. The title on the page hosting the video is incorrect, but the video talks about how cinterop and linking work: https://www.droidcon.com/2022/06/28/sdk-design-and-publishing-for-kotlin-multiplatform-mobile/
kpgalligan
12/15/2024, 7:23 PMkpgalligan
12/15/2024, 7:24 PMDaniel
12/16/2024, 10:27 PMshaktiman_droid
02/03/2025, 9:53 PMand you don't need to use Cocoapods in your Xcode build. There's a flag in that config that essentially says "don't generate cinterop Kotlin bindings"
Based on what I'm seeing, I'm forced to use cocoapods to publish a framework as soon as I add any third party cocoapod dependency in my module.
I was trying to add cocoapods
only for grabbing and linking the binary for compilation and testing and then wanted to publish XCFramework
for my actual KMP library and was hoping that as long as the ios app
satisfies the binaries at run time, it would be okay.
But that's doesn't seem like the case, or maybe I'm missing something.kpgalligan
02/03/2025, 9:59 PMBased on what I'm seeing, I'm forced to use cocoapods to publish a framework as soon as I add any third party cocoapod dependency in my module.Where are you seeing that? In theory, the cocoapods link should satisfy the build, and publishing should be separate. Dynamic frameworks will complicate everything considerably. Static should be simpler. It is possible that you'll need a custom
Package.swift
file that includes the dependencies you reference, but that I'm less certain of. The SPM publishing process doesn't run the same checking that CocoaPods does, so if the framework itself builds, you should be able to publish it. If the errors are on the consuming end, that's a different discussion.shaktiman_droid
02/03/2025, 10:05 PMapi(:a)
• Module A
◦ Add a third party pod()
Now I was trying to export umbrella
as XCFramework and locally use it in native iosApp. No SPM use. Just wanted to copy the framework and use it in native app.
But I can't seem to generate XCFramework
at all. There is no build<Nam>XCFramework
task anymore.
I'll share some code tomorrow to explain betterkpgalligan
02/03/2025, 10:08 PMbuild<Nam>XCFramework
tasks only exist if you configure XCFramework
in Gradle, or use KMMBridge (which configures XCFramework
itself). https://github.com/touchlab/KMMBridge/blob/main/kmmbridge/src/main/kotlin/co/touchlab/kmmbridge/KMMBridge.kt#L76kpgalligan
02/04/2025, 1:46 PMshaktiman_droid
02/04/2025, 2:08 PMshaktiman_droid
02/04/2025, 8:34 PMXCFramework
now. I use cocoapods plugin to include some iOS native dependency. I get warnings like this while building the framework -- can't be exported with -Xexport-library
but at runtime I'm not seeing issues. I have to add cocoapod on Xcode project side, and that's expected because KMP framework would need to link it at runtime.shaktiman_droid
02/04/2025, 8:36 PMembed framework
option doesn't work with cocoapods
. So that was another issue I was facing but that's not a big problem. I anyways wants to export XCFramework
.
Kotlin docs also mention here that the direct integration method doesn't work if KMP has cocoapods dependencies
https://kotlinlang.org/docs/multiplatform-direct-integration.htmlkpgalligan
02/04/2025, 9:05 PMI have to add cocoapod on Xcode project sideIs there a reason you're going through the extra trouble for
XCFramework
if you're already using CocoaPods? Seems like a lot of extra effort.
oh, andThe docs say to migrate if you're using CocoaPods for integration. I've found their docs to not always be complete. Unless the embed task checks and fails if it finds the cocoapods plugin, I think you could use cocoapods with link-only and embed together, assuming you're building a static framework, but I'm not 100% sure. but, again, the docs tend to lean towards trying not to confuse devs with more iOS/Xcode details than necessary. It's something I run into periodically. But, in any case, glad it's working.option doesn't work withembed framework
.cocoapods
I learned that my main issue yesterday was that my umbrella module was empty with no files and somehow that was causing issuesI've seen this. It doesn't see code, so it skips building altogether.
Carl Benson
02/07/2025, 1:33 PMCarl Benson
02/07/2025, 1:36 PMcocoapods {
pod("PostHog", linkOnly = true)
}
in the umbrella module, but I still get
The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
output:
ld: warning: ignoring duplicate libraries: '-ldl'
ld: framework 'PostHog' not found
Carl Benson
02/07/2025, 4:39 PMisStatic
set to false.