What are we going to talk about?
The what could be described as a cross-platform solution for mobile development. But, there is a big difference between a cross-platform solution and Kotlin Multiplatform Mobile.
Looking at the most popular cross-platform solutions, most of them try to bring the web world to mobile.
These solutions often offer one codebase for all platforms (web, Android & iOS) and while that sounds great, it comes with trade-offs. While we can dispute the performance of a native application and a cross-platform solution, an obvious problem is losing the native feel of the application. Android and iOS users expect different things from an application, different UI & UX. And while some of the cross-platform solutions do an ok job at this, it’s never good enough (for me, at least).
This is where KMM steps in. And this is where the difference between multiplatform and cross-platform is most obvious. KMM allows you to share only what you would like to share between platforms. That ranges from something as simple as sharing constants to sharing the whole data layer & all of the business logic. It’s up to you.
Who is writing this article?
I’ve been an Android developer for (almost) 5 years at the time of writing this article. Half of these years I’ve worked with Java. Switching to Kotlin was one of the best decisions I’ve made. While Java has its qualities, I’ve come to realise that Kotlin is superior, at least when it comes to Android development.
After getting comfortable with Kotlin and seeing how it speeds up my development process, I thought it was time to try and improve further. Honestly, I was a bit sceptical when I first heard of KMM, mostly due to my (negative) opinion of cross-platform solutions. Once I gave it a try, I realised the big difference between the two approaches. The technology is still new to me, but it feels really familiar (likely due to the fact that it’s still Kotlin!)
Enough about the who, let’s continue with:
Why would anyone want to use KMM?
As an Android developer, I’m keen on native mobile applications. I want to fully utilise what the system has to offer, including its hardware and its UI/UX.
So, why would I use KMM?
Developing native applications takes time, that’s for sure. And businesses usually want things to go as fast as possible. That’s understandable — it means faster time-to-market, which is crucial. But how to do that, and still get a great native application in the end?
There is a lot of shared logic between applications on different platforms. Ultimately, we want our application to provide the same capabilities on all platforms, but in the native way the users expect. And with two native applications, we have to implement this logic twice. That leads to code duplication and makes the application more prone to errors & differences between platforms. What if we could write this logic once and use it on both platforms — natively?
Well, as you probably guessed, we can do just that with Kotlin Multiplatform Mobile. The end goal is to write the business logic once, expose it to both platforms and use it. This eventually leads to a codebase that’s easier to maintain, easier bug detection, and consistency on both platforms.
The image above shows a nice comparison between native, cross-platform & KMM. And while this comparison may look a little bit biased (given that it comes from KMM’s official site), I’ve come to learn that it’s pretty much true.
Indeed a lot of time is saved by using either cross-platform and KMM, given that you need to write less code. The fact is, that cross-platform edges out KMM in this comparison, mostly because cross-platform solutions also work on the web, but also because of the fact that with KMM, you still have to create the UI twice (which is not bad, but the work still needs to be done). And while Kotlin Multiplatform is working on expanding its targets to the web, in this article we are talking about KMM (Kotlin Multiplatform Mobile), which only targets Android & iOS.
The fact that you can integrate KMM with existing projects is awesome. Any Android or iOS application can start using KMM immediately. Although the integration process is not that smooth yet, it is getting better.
And obviously, the last two items are true for both KMM and native. In fact KMM is ultimately a native application, so the access to platform-specific capabilities and the native performance & feel is retained.
Where does KMM stand?
The first version of KMM was initially released on August 31, 2020. And although that was only just over two years ago, it has come a long way. Kotlin Multiplatform Mobile reached the BETA stage a little over a month ago. And while that might sound like it’s not production-ready, that’s not true.
Kotlin Multiplatform Mobile’s promotion to Beta means that the technology is almost done and is safe to use in your projects. It also means we’ll be actively working to minimize any migration issues you might encounter.
This also gives us the when. When is the right time to start using Kotlin Multiplatform? And the answer is: now. And if you need further proof that now is a great time to start using KMM, or at least give it a try, you can check out some of the case studies on companies that are already utilising KMM in production, including tech giants such as Netflix, Philips, Cash App…