Will Kotlin Multiplatform Mobile change the game for native, hybrid and cross-platform decisions?
Kotlin Multiplatform Mobile (KMM) is a Software Development Kit (SDK) that lets you create applications with a common business logic and native UI components for iOS and Android. In KMM, you share all the common code and create the native UI with the tools that you are used to.
KMM is the new alternative to Native and Cross-platforms like Flutter and ReactNative. The idea is to get the best of both worlds – shared code and native components and speed.
A few years ago, we wrote an article about choosing the right app technology, which compared the benefits of native, hybrid and cross-platform. The article is still otherwise pretty much up to date, but KMM was not yet an option back then, so this article will complement that story.
Benefits of Kotlin Multiplatform Mobile
There are lots of benefits to the KMM. The most important one is that you have the same implementation for features, so they work exactly the same and not just almost the same. Then you also have the same bugs and only need to fix them in one place.
When developing the UI the native way, you also get the latest and greatest UI, just as if you were building the app as two separate native applications. You are not limited to using the framework components and don’t have to wait for the frameworks to start supporting something that Google or Apple have just released in their latest updates.
In one KMM project of this kind currently in production, 52 percent of the code is shared. There are 106k lines of shared code, 55k lines of Android code, and 42k lines of iOS code.
There are still some problems, mainly in the shared interface, or how the shared code (Kotlin) is presented on the iOS (Swift) side. You have to make some wrappers and not all the Kotlin features are supported on the iOS side.
KMM is still in beta, so you can wait for it to improve. Making KMM stable is the top priority on the latest Kotlin roadmap update from December.
iOS developers have to learn a new language similar to Swift when they do development in shared code. When using iOS, the project can currently need a complete rebuild, which takes a long time. You can expect these things to improve later on. There are also still some limits on iOS application debugging in shared code.
Differences between Android and iOS
The shared code is created with Kotlin, which is more familiar to Android developers. On iOS, you have to use the native library interface to access the shared code. The interface is built in Objective-C instead of Swift, which makes it old-fashioned.
Android development is pretty close to what we are used to, we just have to take more care with the shared interface, because both platforms will be using it. The only difference is that the libraries you use on the shared side must support KMM.
You need to decide whether to develop the shared code as a library with versioning or develop both platforms at the same time in the same repository. This really depends on your team size and individual expertise.
Comparison to cross-platform
In cross-platform development, you use the tools and APIs provided by the framework. The framework is responsible for creating the UIs for different devices. This way, you have to wait for the framework to start supporting the latest features of that platform.
With KMM, you are always able to use the latest features. Cross-platform has the benefit that you only need to write the UI once, but remember that it may not feel optimal and native. As another benefit, you can do everything with a single language and tool set in cross-platform development.
When do I start the rewrite?
As mentioned, the best thing about KMM is that you don’t have to start developing your current native applications from scratch.
You can add it to your current native implementations and create new features using shared code. This way, you can add the shared code to your project gradually. And if you don’t like it, you can always switch back to the old way and write everything separately.
Here is a good starting point for developers who want to start developing their mobile app with KMM.
Conclusion and further reading
Despite the fact that this is a new technology and not yet widely known, Kotlin Multiplatform Mobile is a valid option that we believe will become a strong player in the field.
KMM is improving rapidly and worth considering whether you are developing an application from scratch or adding new features or improvements to an existing application.
- Native, hybrid or cross-platform? Choosing the right app technology goes a long way towards commercial success.
- How to choose a programming language for your project? Avoid these biases.
- Two apps for the price of one? Deciding on cross-platform vs native.
Illustration: Midjourney AI