https://kotlinlang.org logo
#ios
Title
# ios
a

Alberto

06/25/2020, 9:23 PM
Does anyone have any suggestions on how to go about creating a single .framework from a bunch of different .klib files?
r

russhwolf

06/25/2020, 10:00 PM
You create an umbrella gradle module that consumes the others, and build your framework out of that module. Though, if you just have raw klib files (vs building them from source in other gradle modules) it might be a pain to set up the dependencies
a

Alberto

06/25/2020, 10:10 PM
Thanks, is there any project available that uses this setup I could check out perhaps?
r

russhwolf

06/25/2020, 10:12 PM
Are you starting from gradle modules or do you really just have klib files? If the former, you can look at any project that builds a framework and just add something like
implementation(project(":myOtherModule"))
to its dependencies. If the latter, I don't know any good samples.
a

Alberto

06/25/2020, 10:17 PM
My idea was the following: create a bunch of separate packages building .klib files, and then have a separate step in merging together those into a single .framework. Reason I was looking into this, is that for iOS each .framework generated for each library is around ~2MB from what I found, so I thought that depending on N .frameworks built with KMP would lead an increase of N*~2MB in the final ipa size. However I just found that even though the .framework is around 2MB, when compressed in the final .ipa size the extra size is more about ~300kB, so perhaps it's more acceptable to just compile against a bunch of .frameworks instead of going through the .klib route. Any suggestions/advices in this area would be much apreciated
r

russhwolf

06/25/2020, 10:19 PM
Right. So if you're merging multiple modules into a single framework, you just have a top-level module that takes the rest of them as dependencies, and that module does the same thing to create a framework as you would usually do
We've been doing some size testing internally and one thing to watch out for is, you don't really get a realistic size until you make a release build and upload it to App Store Connect
a

Alberto

06/25/2020, 10:22 PM
Got it, do you have any rough figures of what is the added size for a simple KMP library on iOS? What I found was around ~300k per library
r

russhwolf

06/25/2020, 10:23 PM
We've found it's comparable to adding the same thing in Swift, with a small overhead from Kotlin stuff that diminishes in significance if there's a realistic amount of code in there
a

Alberto

06/25/2020, 10:27 PM
cool, and is the size supposed to be reduced if having a single .framework generated from a bunch of .klibs versus a bunch of .frameworks?
r

russhwolf

06/25/2020, 10:30 PM
I don't know that off-hand, but if I had to guess a single framework is probably smaller because you're not duplicating any of the Kotlin infrastructure
a

Alberto

06/25/2020, 10:30 PM
yeah that's what I thought, thanks for the info
r

russhwolf

06/25/2020, 10:32 PM
The other thing to keep in mind is, Kotlin frameworks are each their own "world" and produce different types at the Obj-C level. So if you have an kotlin class that's used by two different frameworks, and both frameworks expose that type to Obj-C, then there will be two incompatible copies of that type in Obj-C. So you have less flexibility to talk between modules at the Obj-C level if you have multiple frameworks
a

Alberto

06/25/2020, 10:49 PM
Got it, makes sense
2 Views