If I had to guess, you landed on this page because you’re looking for the ultimate hack that facilitates cross-platform app development.
To be more specific, you’re probably researching for the best solution that can share code between iOS and Android while respecting each platform's distinct environment and user experience. You’re in luck because Kotlin Multiplatform is the technology you’ve been looking for.
Kotlin Multiplatform is a genuine cross-platform SDK. With Kotlin Multiplatform, you can write once and test once. Companies can effectively reuse the same code across Android, iOS, and web apps. In effect, your business won't need a full complement of separate development teams for each platform.
Depending on the nature of your application, up to 70% of code can be shared between platforms. Your development team only needs to write code once and all new releases are propagated immediately to all targets. All your customers can seamlessly benefit immediately from updates as the same business logic gets pushed to all platforms.
This may sound too good to be true. So in this article, I’ll go into some detail on when to use Kotlin Multiplatform when developing an app. Before that, I’ll briefly introduce Kotlin Multiplatform and how it stacks up against Flutter and React, its alternatives for mobile cross-platform development.
What is Kotlin Multiplatform?
Kotlin Multiplatform (KMP) is an SDK that supports cross-platform app development by enabling developers to write the same business logic for multiple platforms. Kotlin Multiplatform allows development on other platforms such as Linux, Windows, and web apps. In addition, KMP’s subset Kotlin Multiplatform Mobile (KMM) enables developers to code business logic for iOS and Android from a single codebase.
KMP was released in 2017 as part of Kotlin 1.2. It’s the result of a long-running (and still ongoing) effort by JetBrains to reduce time spent on creating applications targeting multiple types of devices, such as desktop computers, Android and iOS powered smartphones — all thanks to the power and flexibility of Kotlin. In addition to the sharing of business and data logic, it can also facilitate the sharing of UI in certain cases, with the help of Compose Multiplatform.
Even though KMP is considered to be still in its alpha stage, according to a survey conducted by JetBrains between Q3–Q4 of 2021, almost 28% of mobile developers who responded were already using Kotlin Multiplatform in building their applications.
Some of the widely recognized corporations and apps that use Kotlin Multiplatform include Target, Autodesk, Trello, CashApp, and VMware, among many others.
What about Flutter and React? Where does KMM shine?
After hearing about Kotlin Multiplatform Mobile, you might think that things are getting out of hand — one technology appears after another, and the market gets even more fragmented than it was before. You’d be right to think that. But such is the way of software development — that trends and technologies surface overnight, and some of them disappear even more rapidly.
Fortune favors those who make the right bets that resonate with the market. Let’s analyze the differences, then, to make sure you choose your technology correctly.
|UI rendering||Native — separate UI for Android and iOS||Non-native — shared UI rendered using custom graphics engine||Semi-native — shared UI translated to respective native components to render|
|Business logic||Written in Kotlin — shared between platforms||Written in Dart — shared between platforms||Written in JS — shared between platforms|
|Total % of shared code||Up to 70%||100%||100%|
|Technology maturity||In alpha since August 2020||Stable since December 2019||In beta since March 2015|
You can expect a more in-depth comparison between KMM and those two technologies in separate Netguru blog posts, but the main gist is this: the amount of code that can be shared with KMM will ultimately depend on features you’re trying to implement.
If your app mostly serves as a frontend to consume your REST API backend (for example, an app displaying products or discounts), with KMM, you can write that logic once and serve it to your native UI’s.
While it may not seem like the best idea to make use of KMM in your app with what I’ve discussed so far, there are ecosystems and business decisions that fit especially well into the paradigm of Kotlin Multiplatform. Here are the situations when you should consider adopting Kotlin Multiplatform for your application development.
Kotlin Multiplatform RnD retail project by Netguru
You already have an Android app
There are markets that are mostly dominated by Android, such as Asia, where as much as 80% of users own an Android-based smartphone. It’s logical to develop an app only for that single target. But let's suppose that you want to expand your reach to Europe or North America later — markets where iOS is more on par with Android’s reach.
Now imagine that instead of developing another native application that will duplicate all the code you’ve already written, you’ll only have to provide the native UI and reuse the logic your developers have previously created. That’s the power of Kotlin Multiplatform Mobile and its core strength — it allows companies to grow existing business at a smaller cost.
You could also take a step in a different direction: create a desktop application that offers the same functionality as your Android app. It might have been unprofitable to create it from scratch, but thanks to Kotlin Multiplatform, your development team can reuse the existing business logic and, by employing the Compose Multiplatform framework, you can even share UI components.
You plan on expanding your existing native apps
Let’s say you’ve already invested into creating separate Android and iOS apps, and they don’t share any common code. With Kotlin Multiplatform, that’s not a problem! You can adopt KMM at any point and share as much or as little business logic as you wish.
When you start adding new features, you can then think about sharing code between platforms without refactoring all that you’ve done up to that point. Alternatively, you can begin to refactor at your own pace if you wish to have a codebase that only needs to be maintained once without separate updates to the Android and iOS components.
You rely heavily on native UI solutions
While Flutter and React Native do their best to offer similar functionalities to what native UI offers, there are quite a few situations where one might benefit the most from going native. Features involving the camera, augmented reality (AR), machine learning, or complex animations are a great fit for Kotlin Multiplatform Mobile.
Similarly, if you want to target the newest capabilities of the most recent OS versions, KMM is the right fit for your project. This is due to the fact that the core business logic can be shared, and the user experience remains native and as closely integrated with the system as possible.
Kotlin Multiplatform RnD retail project by Netguru
Additional advantages of Kotlin Multiplatform
In addition to these circumstances when you should consider Kotlin Multiplatform for your project, here are more advantages you ought to know.
- Fast growing community of developers for Kotlin, KMP, and KMM: A lot of enterprises and startups are already adopting the Kotlin programming language, along with KMP and KMM as a result. This isn’t surprising following Google's declaration of Kotlin as its preferred language for Android. Online resources on how to get the best out of Kotlin Multiplatform continues to grow indicating the growth of its community. Further, the talent pool for KMP developers whom you can hire will likely expand further.
- Improved code quality and maintainability: Having a shared codebase can facilitate better communication between iOS and Android developers, which can result in discovering more mistakes early in development. This would likely lead to functional consistency among apps. Another related advantage is the multiplatform code's intrinsic modularity and testability.
- Faster or more efficient development timelines along with cost reduction: It’s entirely feasible to save 30-50% of development time by using Kotlin Multiplatform for mobile and web development. When compared to Java, Kotlin can save 40% of code lines. Furthermore, because Android and iOS apps use the same lines of code for business logic, it’s easier and quicker to introduce and test additional features. In effect, Kotlin will likely help your project cut on cost because you won’t have to build full teams for each platform or pay developers for writing the same lines of code twice (or even more).
Relatedly, Kotlin enables development teams to collaborate more effectively and focus on upcoming tasks. Project managers can efficiently divide tasks among team members. For instance, while the Android team might work on user signal inflow, the iOS team can work on post-create flow. The Android team can then include the code written by the iOS team in the next sprint, or vice versa.
Is KMP the best solution for cross-platform app development?
While Kotlin Multiplatform is still in alpha, it already offers extensive use cases for business. So is Kotlin Multiplatform the best cross-platform technology out there?
As I see it, KMP doesn’t serve as a direct replacement for Flutter or React Native. Rather, it complements native development, making it ever more appealing thanks to reduced costs of development and maintenance. Kotlin Multiplatform is essentially a go-to solution to help meet the increasing need for apps to be available on numerous platforms through a pragmatic approach by avoiding having to write code twice.
Further, KMP has an edge when it comes to the optionality of code sharing. Teams can start little by little, feature by feature. You don’t have to scrap what you’ve already built. It’s a low-risk approach wherein businesses don’t necessarily have to commit to a big decision. So why not try it out?