Hi all, not sure if this was the right channel to ...
# kotlin-native
j
Hi all, not sure if this was the right channel to ask this. I created a Multiplatform project with Kotlin 1.3.20, a Native target for iOS and using Kotlinx.serialization 0.10.0. I could successfully create the Framework and use it in iOS but in order to make it work in iOS I exported the native serialization runtime library to be included in the framework like this:
Copy code
iosX64("ios") {
    compilations.main.outputKinds("framework")
    binaries {
        framework {
            export "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.10.0"
        }
    }
}
My question: Is there any way that I can avoid doing this and add this dependency in the iOS project? (using the kotlinx repository which is bintray right now) I’m asking this as I would like to start creating more Frameworks that depends on this serialization runtime but I don’t want to include it in every framework, specially if those frameworks are going to be used in the same iOS project.
r
Generally you should only have a single framework per iOS app. If you want to modularize your Kotlin Native code, create multiple klibs and then combine them into a framework at the end.
j
Well this sounds ok for small projects. I’m not sure about big projects were we have several teams working in different features for the same App and, as we work today, we have tons of independence between the teams. Having a single framework sounds like a bottleneck, specially for build process 🤔. It would be great to have a dependency manager like we already have in Android (gradle) and iOS (carthage) but for native dependencies
s
I haven't done this personally, but you can use maven to distribute klibs for the native platform. I think this is enough to suit your needs.
j
It's true that you can solve dependencies but I'm still not sure which approach to use for the case that I mentioned at the beginning, where you need to export the lib that you depend on and every framework that you create will have to have this exported dependency, creating fat frameworks with repeated code if they have the same dependencies
s
Also, I'm pretty sure you could compile a kotlin lib to whatever Swift compiles too and distribute it with cocoa pods or carthage.
r
I haven’t tried it out yet but @alec put out a plugin to help with cocoapods https://github.com/AlecStrong/kotlin-native-cocoapods
j
Thanks @russhwolf! The plugin is to publish the generated framework with cocoapods and use it locally so you don’t need to manually add the framework to the iOS project, it’s just an alternative but not really solving the “export” dependency
@spierce7 I think that’s feasible but that would mean that I have to publish as a Framework all the dependencies that I want to share between my klibs? like publishing a framework of kotlinx.serialization so it can be reused in my different generated frameworks right?
s
All Kotlin code is supposed to be published as klibs.
j
@svyatoslav.scherbina how can I solve my problem with exported libs? In my first comment I left an example
s
What is your problem if you don’t have multiple frameworks?
j
right now I’m creating a framework with the exported dependency of kotlin-serialization. I want to create a second framework, independent from the first one that provides another logic but also use the kotlin-serialization dep, which means I have to export it in again. So I end up with 2 frameworks that internally have the code of kotlin-serialization repeated
I have to mention that both frameworks are going to be used in the same iOS app
s
As was already mentioned above, you can’t use more than one Kotlin/Native framework in the same iOS app.
j
Just to understand more, why we cannot use more than one? Technically is possible as at the end it’s just a Framework. I see it as a “jar” for Android. Another question, if the idea is to go with klibs that means that we are going to end up having a big Framework including all the work created by different teams for the same app right?
s
Just to understand more, why we cannot use more than one? Technically is possible as at the end it’s just a Framework.
Technically it is limitation of Kotlin/Native currently.
Another question, if the idea is to go with klibs that means that we are going to end up having a big Framework including all the work created by different teams for the same app right?
Right.
j
Thanks @svyatoslav.scherbina for the quick answer