My Kotlin Multiplatform Mobile learning curve
The opinions in this post are my own and do not reflect the views of SuperAwesome or Epic Games.
It’s been 17 months since I joined SuperAwesome as a fresh-faced Mobile Engineer. My only cross-platform experience was with Flutter and I’d mostly developed native Android apps.
SuperAwesome had taken the Kotlin Multiplatform Mobile (KMM) route — you can read about that decision here. This post is about my KMM learning curve and experience building out the PopJam and Rukkaz apps using the SDK.
What is Kotlin Multiplatform Mobile?
Kotlin Multiplatform Mobile is an SDK designed to simplify creating cross-platform mobile applications. With KMM, you can share common code between iOS and Android apps and write platform-specific code only where necessary. This means you can implement native UI while only writing the business logic once.
TLDR
KMM is easy to pick up if you’ve built Android apps. It takes a little longer for iOS developers but there’s still enough native iOS work to go around while they learn the Kotlin needed to contribute to the KMM common module.
~35% of our Rukkaz app’s mobile codebase is shared between iOS and Android. Engineers can write logic which both apps share, resulting in more consistency across the two platforms. Compare this to trying to implement the same logic separately for Android and iOS. It’s much easier to keep it in sync.
It’s easier to pick up if you’ve built Android apps before
An advantage of KMM compared to React Native or Flutter is that if you’ve already developed native Android or iOS apps, you don’t need to learn a new tech stack. React Native requires learning Javascript and Flutter uses the Dart programming language.
This meant that when I joined SuperAwesome as an Android engineer, it was much easier to get up to speed. I already knew Kotlin and many of the KMM libraries are similar to their Android equivalents. This gave me the time I needed to upskill my iOS development.
While the learning curve is a little steeper for iOS engineers, you can do the reverse of what I did and work on the native iOS UI while learning Kotlin (which is similar to Swift).
~35% of our mobile code sits in the Common module
What that means in practice is that almost all of the business logic (e.g. view models) and the networking layer only has to be written once. Every bug fix and improvement to that common code is leveraged by both platforms.
The other advantage is only having to write and maintain one set of unit tests. Good news for any developer!
You’re still able to explore the latest iOS and Android technologies
iOS and Android apps are different and should feel different. There’s a reason Flutter and React Native apps often don’t quite feel right. KMM enables native UI development, meaning apps can be built to feel snappy and fluid.
The other benefit is getting to take advantage of the latest in iOS and Android developer tools. In 2021 that meant SwiftUI and Jetpack Compose!
Given that our UI is native, it’s been just as easy to start migrating from XML to Jetpack Compose and from UIKit to SwiftUI as it would have been if we’d had standalone Android and iOS apps. So we get to take advantage of those slick native animations and screen transitions while getting the declarative UI and hot reloading benefits that Flutter offers.
Well, almost all of the latest iOS and Android technologies
As great as KMM is, there are some trade-offs to consider.
One that stood out for me as an Android developer is that given our view models are part of the shared KMM code, we don’t use the Jetpack ViewModel class. This means there’s a little extra work to do on Android to ensure our view models store and manage UI-related data in a lifecycle conscious way.
That said, there are now KMM libraries where components are lifecycle-aware on Android such as moko-mvvm.
I began as an Android engineer. Now I’m an iOS engineer too
When I joined SuperAwesome, I had limited iOS experience. I started out working on the KMM and Android modules. Given I was effectively building ⅔ of a feature across both platforms, it quickly made sense to develop my iOS programming so I could build the complete feature for both. The fact that 35% of our code is shared afforded me the time to do this.
All of our mobile engineers now work across both platforms.
Getting started with Kotlin Multiplatform Mobile
KMM was developed by JetBrains. Their documentation includes starting a KMM project from scratch or making an existing mobile app cross-platform.
If you want to dive deeper, John O’Reilly’s engineering blog covers a range of KMM topics. It includes a demo, PeopleInSpace, which showcases how the declarative UI frameworks Jetpack Compose and SwiftUI can be used with the KMM SDK.