I'm Android developer and I know nothing about iOS...
# multiplatform
t
I'm Android developer and I know nothing about iOS. But now they want to build KMP library usable on iOS. Is this still valid? It is 2 years old. https://stackoverflow.com/a/70268019/504179 I mean that it is not possible to share complex data between multiple xcframework based depdendnecies. Or even create dependency between them. The official documentation just telling, that suggested way is to create one umbrella module and build only xcframework zip. But if I have for example 10 different libraries that has dependency between each other and two iOS app which one needs just 3 and second one need all of them. I will need to build special ZIP for every app with mix of all libraries they needs? https://kotlinlang.org/docs/native-spm.html#exporting-multiple-modules-as-an-xcframework
p
Some people have managed to include multiple kmm frameworks in Xcode but still the recommended way is using just 1 kmm
shared
framework that includes all your needs. These will avoid duplicate kmm runtime inclusion which will impact size mainly. Also having all modules together when compiling can take advantage of optimizations. In your case you can have 2 shared(umbrella) modules as you mentioned. One
shared3
importing 3 of your modules and the other
sharedAll
which imports all of them.
t
I know that it is possible to include multiple frameworks, but they probably must be fully independent you are right, that both will probably have duplicated all kotlin stdlib classes.
But technically frameworks can have dependencies. So theoretically would be postile to have stdlib as one framework and then all my libraries depended on it. But currently it is not supported by KMP, right?
Solution is also don't use clean iOS projects but use only KMP project even for iOS.
I mean only add
shared
kmp module folder to existing iOS folder with all the librarries depenendencies that project needs and setup it in the way as normal kmp project is. It mean that XCode will run gradle task which will build native library locally from .klib dependencies.
p
An iOS framework is just a container for code, either source/(binary or compiled). But it by definition doesn't have a way to declare its dependencies. Same as a
jar
or an
aar
, they need a pom.xml file so a build tool like maven or Gradle pull the dependencies into the compile/runtime whatever path. Similarly in iOS, SPM or cocoapods or cartridge have their own mechanism to declare dependencies. But if you distribute a raw framework, your clients will have to manually add the other dependent frameworks in Xcode. This is the case for a dynamically compiled framework. On the other end, you can distribute a static framework which embeds its dependencies in the binary but it obviously will impact size. Because if the client also depends on the same transitive library you include the binary bulk twice in the final(App) binary. That's why dynamic compilation/linking is preferred over static compilation/linking. Back to kotlin, KMP is not an iOS build tool so you can't tell it which iOS dependencies your library depends on. (The cocoapods KMP gradle plugin allows for this but enforces you to use cocoapods in iOS side, and FYI the cocoapods project just entered maintenance mode this year) So the only thing KMP does is produce a framework. You can certainly depend on other KMP libs(.klib) but not other ios frameworks, they are not supported, at least yet.
In regards to the project setup it depends what is more comfortable for you. If you are heavily developing in both KMP and Swift, at the same time and the changes you do in KMP you want to apply them immediately in Swift. Then the setup you describe will work for you. That is basically a development setup. However for a pipeline I would not use that setup but will depend on the final
shared
framework already compiled. For faster build times.