So my iOS team needs me to provide them a framewor...
# kotlin-native
s
So my iOS team needs me to provide them a framework, but that framework needs to support several different kotlin/native platforms, while being compiled to a single framework. Are there any examples of doing this, or would anyone know how?
d
Hey @spierce7; do you mean you need to bundle e.g.
iosArm64
and
iosX64
into the same
.framework
e.g. for SDK distribution?
Oh, I see above. To combine what Apple call 'slices', then for a static
.a
library files the answer is to use a command line tool called
lipotool
(A play on making the library 'fat')
For a dynamic
.frameworks
, where a framework is really a folder containing one or more
.dylib
files, there's probably a convention for file-naming and/or specification in the framework's
Info.plist
Since yours is primarily an iOS question rather than a Kotlin one.
Once you know how iOS deals with 'Universal Frameworks' then you can make the Kotlin output match it 🙂
Looks like it'll take some Gradle work to compile multiple targets based on the iOS Presets you need, followed by marshalling them into one
.framework
file.
s
You are starting to lose me a little. This is all pretty new to me. So all I know is that my ios team compiles to multiple CPU architectures. I need a way of providing them my kotlin library as a framework, and I'm assuming that means that I need to provide them a single framework that has all the CPU architectures they need, or a way for them to hook up the same framework multiple times for different CPU architectures.
When I looked at other frameworks distributed via Carthage, they are providing a single framework
d
Take a look inside that framework file
It's actually a folder - how many
.dylib
or other binary files do you see?
j
there's a FatFrameworkTask gradle task that takes care of lipo etc - you might want to look that up
👍 1
a
Hey. This is something I struggled with a bit (being primarily an android dev). I used the lipo tool to achieve this. First notice the
packForXCode
task, it should look similar to ones you have seen before in the documentation, just slightly adapted to have a custom name and use the target name. Then I have two tasks
packForXCodeArm64
and
packForXCodeX64
which set the relevant params and then call
packForXCode
.
copyFrameworkSupportingFiles
copies a load of files from one of the targets frameworks into the new combined framework. My understanding is that the binary file is the only file that will actually change based on target, so you just need all the other files from either target (e.g. headers)
combineFramework
task then uses the lipo tool to combine the two targets binaries.
createFramework
is the task I actually call, which just orchestrates the various other tasks. There may be better ways of achieving this, but that’s where I have gotten to so far. I am using kotlin: 1.3.41
t
s
wow... this is awesome. Thanks guys!