I am trying to consume a kmm library in my native ...
# multiplatform
a
I am trying to consume a kmm library in my native mac os app. I used the tutorial at https://kotlinlang.org/docs/apple-framework.html but i am really lost towards what to put in the Search Paths so it works both for x86 and arm64 I can hardcode the path to the lib, but how can i make it work for both x86 and arm64? I had a look at @John O'Reilly’s PeopleInSpace and in his configuration the files are read from
$(SRCROOT)/../common/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)
. I had a look at the kmm common module and there is indeed a
xcode-framework
with the name specified in
CONFIGURATION
and
SDK_NAME
. how is that created? Feel like i am missing something fundamental
w
Hey alex, looks like he’s using a gradle block for that:
Copy code
multiplatformSwiftPackage {
    packageName("PeopleInSpaceKit")
    swiftToolsVersion("5.9")
    targetPlatforms {
        iOS { v("14") }
        macOS { v("12")}
    }
}
a
I saw that, but not sure what to do with it. I added it to my project same was as People in space, but when I did
./gradlew createSwiftPackage
or
./gradlew createXCFramework
it creates those folders in the root of the directory. not with the naming i can use in xcode
w
right, that runs the standard kmp task
i think the plugin generates a separate task for bundling the swift package
a
the gradle commands i wrote above are the gradle tasks it creates
w
oh whoops I only read the second one. I thought createxcframework was a default task…
You would think that the first task would build the artifact… I’m sure you’ve set frameworkname or otherwise basename. Not sure what’s going on here
What happens when you try to manually change output dir?
outputDirectory(File(projectDir, "swiftpackage"))
You might need to
apply false
for the plugin at root project level, if you have modules
a
i don't. it's just one kotlin project
👍 1
Turns out the library is unrelated. It is used to consume Swift Packages in KMM
👍 1
w
Gotcha… Looks like I had it the other way around. So just add all apple compilation targets to the xcframework?
a
what does that mean?
w
How are you accessing the kmp library in swift?
a
I don't. that's what i am trying to do
w
From John’s article, you can use cocoapods + xcframework or the gradle plugin
unless I am misunderstanding things
a
john's article is about consuming swift packages in kmm. I am trying to use kotlin mm in my mac os project
w
You’re right the intro paragraph though describes how people commonly integrate kmp into mac os, and how xcframeworks for different plats can be bundled into one swift package (with the gradle plugin, or otherwise)
a
i see what you mean. i just noticed that you can distribute the package localy by doing `
Copy code
distributionMode { local() }
I am trying to figure out how to use that in xcode
👀 1
w
Are you running one of these tasks as an intermediary?
assembleXCFramework
assembleDebugXCFramework
assembleReleaseXCFramework
a
It worked!
🙌 1
1
😁 1
What I did was created a local Swift Package using the plugin and then
./gradlew createSwiftPackage
, and then add it in xcode via My Target-> General -> Frameworks, Libraries and Embeded Content
w
Ahhhh thought so
wait but was createSwiftPackage not working before? does it build the xcframework or do you have to do that step?
a
I used createSwiftPackage before but it was not created the folders i saw in John's project
I think what's happening in people in space is that John is not using the kmm module directly and that's why i was so confused. he must be using the package distributed in github
as described in the article
is that right @John O'Reilly?
w
the SwiftExecutablePackage folder? Yeah, looks like an artifact dir
a
that is probably a cli app
w
looks like it
w
Not sure if this repo is just the output of the gradle task…
I think he builds xcframework from main repo gradle tasks, copies into this packager and exports the swift lib
this project is likely just a module of the main repo though to take advantage of that gradle plugin
j
A bit late to party here but sounds like it was sorted out. BTW have another dedicated swift package repository here https://github.com/joreilly/BikeShareSwiftPackage
The output of plugin, as was mentioned above, is pushed to the other repository.
and can then use url for that repo in Xcode
There's another reason I've also done that recently for another project.....the main repo in that case uses git-lfs and can't seem to be able to use such a repo when adding in Xcode
another approach I've been looking at recently is use of KMMBridge from Touchlabs....provides some additional flexibility and also advantages to how the xcframework binary is hosted (avoiding potential issues with associated gh history for such binaries) https://touchlab.co/kmmbridge-quick-start
👀 1
cc @kpgalligan
k
Yes, I would use that 🙂
I didn't read the whole thread. Long thread...
w
No need! Have been looking into SKIE too.
k
In summary, keeping the binaries in the repo is rough. git-lfs is something that might work, but ugh. KMMBridge (by default) will push it to GitHub packages, which doesn't have the same size issues.
👍 2
But, there's something new coming. Not exactly for this use case, but still. To be continued...
👀 2
😁 1
Just curious. Is there a reason to publish vs just adding a build step to Xcode and directly pulling in the KMP code?
Why a separate lib and repo?
w
He automates builds with GH actions
j
here's a bit more background on that issue......it's relatively old post but I was seeing issues recently enough as well.https://forums.swift.org/t/swiftpm-with-git-lfs/42396
btw this was for repo that was using git-lfs for something different (screenshot testing artifacts....in https://github.com/joreilly/Confetti ). ....if not using that then you shouldn't have this issue
w
Is there a reason for this project? LFS isn’t enabled in this one?
(people in space)
j
reason for it being a separate repo?
w
Yeah, I think that’s what Kevin asked
j
I think at the time I just wanted to keep them separate
no technical reasons I think
👍 1
I haven't looked at this in a while but I believe Xcode will clone full repo of gh url you provide when adding package....I felt at the time I think that it would be cleaner/faster to have repo that just contained the package
w
Facts… deep clones take too long
I mean, it’s trivial but unnecessary. Just adding extra time
j
For Confetti we'd started exploring using KMMBridge.....though need to confirm it's still working with latest code. You can see
Package.swift
for example in the repo (https://github.com/joreilly/Confetti/blob/main/Package.swift) and one key thing here (and different to approach of say PeopleInSpace) is that the binary it points to is hosted elsewhere
🤔 1
all of this is managed by a gh action that KMMBridge provides
k
Yeah, my question is more about why separate repos vs just building the Kotlin directly with an Xcode run script. For Confetti, the ios code is in the same repo (as far as I can tell). Why the publishing at all?
For native mobile teams adopting KMP, the added "SDK PR/Publish" step becomes a major blocker to dev efficiency.