Kotlin Multiplatform (KMP) — 🧐 or 🙈!!
Droidcon Italy 2022, was full of learnings and interesting conversations around various tech getting build in Android world.
One of the interesting discussion was “Kotlin Multi Platform Roundtable”.
For the starters it was a brief intro about kotlin multi platform. Is it just another cross platform development solution or what makes it different from other solutions.
Kotlin Multiplatform is an approach that allows engineers to share code and key business logic across various operating systems.
With Kotlin Multiplatform, software engineers can reuse business logic on both the client (front-end) and server (back-end) sides running in the browser. It allows for sharing key business logic across numerous targets that involve Android, iOS, JVM, macOS, tvOS, watchOS, and Windows, JavaScript, and WebAssembly.
However, while Kotlin Multiplatform is a cross-platform technology, it does not support the “build once, deploy everywhere” approach.
With KMP, it is possible to reuse the multiplatform logic and code in either common or platform-specific code and it return it enables teams to reduce product delivery time along with advantages of native application development.
So after the starters, it was the time for main course. And few questions on the menu looked like this :
1. How to convince iOS developers or web developers for choosing this solution ??
There were many thoughts around this, in gist it was to start the journey with a very small use case and working towards building it. Not to rush to refactor or restructure entire code base.
Start becomes easy if there is a simple use case and team including ios and android devs start working on it. This journey will be a learning curve for ios devs, as they need to learn kotlin for developing in KMP.
Learning kotlin is not that tough for ios devs due to it’s share similarity with Swift. Fingers crossed for this 🤞
2. How KMP has evolved so far ?? 🧐
KMP has evolved a lot from its inception !!
Now when you think of creating a KMP project it’s pretty easy.
Just insert template, add logics, compile it and your small project is ready to execute on both Android and iOS ecosystem. No more compiling issues and now debugging the code has become pretty easy as compared to initial days.
Not only that, the new Kotlin/Native automatic memory manager lifts the existing restrictions on object sharing between threads and provides fully leak-free concurrent programming primitives that are safe and don’t require any special management or annotations from the developers.
New versions of kotlinx.coroutines and Ktor libraries are already benefiting from this new approach in KMP, so you can freely launch coroutines using a multithreaded background dispatcher without having to freeze objects that work in background threads. So now multi threading is solved too so it’s way easier to start using KMM in your projects to make your existing Android application work on iOS and to create new features for both platforms simultaneously. Isn’t it cool enough 😄😎
3. How does your pipeline will change if you start using KMP ??
If you look at the Kotlin documentation in detail, you will find a section on publishing multi platform libraries .
Kotlin Multi platform developers are aware of the multiplatform building issues (not everything can be built on all operating systems) and offer the option of building the library separately on different operating systems.
We discussed a bit around Nate Ebel journey on building the workflow and github actions to publish builds for android and iOS. More details could be found here : https://engineering.premise.com/kotlin-multiplatforrm-github-actions-workflow-3e5e0fcb7081
4. Are you using Native UI’s with KMP or thinking around compose in KMP ??
This was a fun topic to discuss where few opinions were to use compose in KMP to build UI , where as other felt it’s good to use KMP to share business logics but in terms of UI it’s good to keep it more authentic with native feel.
It depends a lot on time to market for your product too, if you already running tight on that it might not be a right choice for using different ui foundations. If you are writing from scratch it could be good choice to do it 100% composable widget and use it across platforms and in second iteration take a step towards giving users a native feel.
5. Is it safe to use a library in production which is in alpha ??
Agreed on this point that KMP is in alpha since long, but it’s true that it’s way better than some libraries in beta 😉. So feel free to use and if there is any issue that there is huge community out there to help you out.
And to wrap the discussion the last question was:
6. How to convince your CTO to use KMP 🤓
This seems to be the most hardest question to answer !!
Where there is a will, there is a way !!
Figure out the best use case for this problem statement and let the team reach to this solution. It becomes easier to solve a problem when whole team including ios and android devs think alike. Once whole team want to try out KMP, go towards the solution, making sure that feature toggles are ready to safeguard you in times of need.
Trying something new is always a roller coaster ride, feel free to share your experiences of the journey.
Happy coding !!