What is KMM? Is Multiplatform programming is going to boom!?

Pavitra Raut
5 min readOct 17, 2021
  • Writing a single program or an application which can be deployed on multiple platforms can be termed as Multiplatform programming.
  • It changes the way, we think while delivering new functionalities.
(Fig 1) Usage stats of multiplatform frameworks
  • There are many frameworks (represented in Fig 1) which helps us to achieve multiplatform programming like React Native (by Facebook), Flutter (by Google), Cordova (by Apache) and many more.
  • The main advantage of these frameworks are that you just write code once for your app and use it for deploying on different platforms seamlessly (which follows DNR principle).
  • But the problems with these options are that they do not feel native and are not as performant compared to native apps (although it is getting improved day by day).
  • Moreover, to write your application using these frameworks, you need to learn its own language sometimes (e.g., Dart language for Flutter or JavaScript for React Native) which can concern some experienced native developers.
  • Apart from this we can all concur that Non-native adaption apps’ sizes are more compared to Native versions.

Wait… Pavitra, above points, it doesn’t justify the title. — Yeah, I know, but I found a framework which can… wait and watch 😎

Kotlin to the rescue

  • Kotlin has introduced its own approach to multiplatform programming.
  • Support for multiplatform programming is one of Kotlin’s key benefits. It reduces time spent writing and maintaining the same code for different platforms, while retaining the flexibility and benefits of native programming.
(Fig 2) Kotlin multiplatform support
  • For this session we will be specifically focusing on KMM.

What is KMM?

Let us start with what is KMM (Kotlin Multiplatform Mobile). It is an SDK for cross-platform mobile development. Its core focus is to allow you to share parts of your application, primarily between iOS and Android.

The difference is, its approach, which is “Bottom— Top” approach (only your business logic will be in Kotlin, but UI related code should be in native) represented in Fig 3.

(Fig 3) High-level architecture of KMM

Whereas on other Framework, you can write most of your code in a single language, and while executing, executes inside some kind of container as represented in Fig 4, which somewhat hits app’s performance.

(Fig 4) High-level architecture of most other similar frameworks

So what?

KMM seems promising and can help us to maintain our shared code efficiently.

  • There is No overhead as it compiles to byte code for Android and native for iOS.
  • Requires less effort on testing.
  • Bug fixes and enhancements can be quickly and easily pushed out.
  • Shared business logic are mostly independent of the platform, which takes care of separations of concerns.
  • Kotlin and Swift are quite similar languages, so iOS devs can easily learn to write Kotlin code.
  • Ability to use platform-specific libraries in KMM project using Gradle (for Android) or CocoaPods (for iOS) which opens a whole new world of ecosystem.
  • Easier to migrate if using Kotlin with MVVM pattern for our Android project.

Below are few components which you can easily share using KMM:

  • Data Models
  • Serialization from API JSON
  • API Authentication and Calls
  • Analytics related codes
  • Monitoring of exceptions and problems
  • Caching

Case studies

Here are few case studies that have adopted or are adopting to KMM

Now what?

  • The first factor that motivates us to use KMM is that we can have an Android & an iOS native application without the double effort.
  • We can easily save 30–40% of our effort as we don’t have to do the job twice.
  • Other thing is that KMM uses totally different approach compared to other frameworks, so no more learning of new languages or performance hits on app.
  • Initially we can start with small projects of our organization and then gradually start migrating major projects.

But…

Just like any new SDK that you adopt which is in Alpha. There have to be some cons to using it. Here is what I have found searching around so far:

  • Version upgrades of Kotlin Multiplatform Libraries can be hell and time-consuming (but having a good test harness helps).
  • You are often living on the edge, as a lot of the libraries are in alpha or beta.
  • Exceptions or errors on iOS can be hard to debug because they are obfuscated by Kotlin.
  • Some basic data formatting functions (like String formatting) are not available out of the box for iOS and Android.

If you are still reading, then I suppose you liked this story, so please show your love by clapping and motivating me for my upcoming stories.

Photo by Patrick Fore on Unsplash

--

--