Hello everyone! I want to do a research about code...
# multiplatform
g
Hello everyone! I want to do a research about code sharing with kotlin between android/IOS for my company. If my goal is sharing all the code, except UI and platform dependent stuff but including DB and networking, should I look into kotlin-native or multiplatform? Is there any projects on github with something similar?
g
You can of course compile K/N for Android as native binary, but if you don’t plan to use some NDK specific API I would avoid this option and use Kotlin/JVM and Android SDK instead
g
Thank you for the answers! But is it possible to share http networking implementation for both platforms this way? I mean if I would use K/N for iOS and K/JVM for android.
t
@gvoltr absolutely and there is even ready to use library - ktor
g
Thanks again! Will try it out.
g
Check documentation about Kotlin multiplatform, there are approaches how you can share business logic and use platform specific APIs like networking
g
Thanks! Will definitely check this out. My first goal is check how much code can be shared potentially. And then discuss with coworkers and decide is it worth to make things like networking cross-platform or keep platform-specific implementations.
g
it’s not real cross-platform networking in case of MPP, implementation of each platform is different, but you just write thin layer of abstraction (or use ktor-client as ready to use solution) There is no easy way to share implementation, only use native library compiled for Android and iOS but it’s big pain to use such native code from Kotlin/Java, you need JNI for this MPP approach is much better imo
k
We have a fairly complete app sample with dB and networking. The dB part is probably the most “production like”. Networking should be updated to ktor. Threading is kind of a minimal implementation. Expecting multithreaded native coroutines lib in the near future https://github.com/touchlab/DroidconKotlin/
g
Thanks a lot! That’s what I was looking for.
👍 1