Aleksa Simic
July 3, 2024
•
8 min read
Ever since I started my career as an iOS engineer, I always wanted to learn about how Android development works and maybe one day, develop an app for both platforms.
However, I have always felt that I want to master iOS development first, before learning more about any other technology.
And it was just like that, after 7 years of working heavily in the iOS ecosystem, on more than 20 different iOS applications, totally unexpected, I had a chance to dive into Android development just a little bit, thanks to the new piece of technology called Kotlin Multiplatform, or shortly, KMM.
But before having a chance to work with KMM, I had a chance to try out the other cross-platform tools like Flutter and React Native also, and see how they compare to native development, and whether are they interesting enough for me to dive in more and master them.
As for the Flutter, I went through the whole course by Angela Yu, by the way awesome course, and I would recommend it to anyone starting to learn Flutter. It was pretty fun, I am not gonna lie, made a bunch of smaller Flutter apps, and figured out how the UI building itself is pretty similar to SwiftUI and Compose. Because of that, the UI part was pretty easy for me to grasp, but I had a sense that it would take me too much time to learn Dart in-depth to write code in Flutter on a high level so that’s pretty much where my Flutter journey stopped.
As for React Native, my only experience with it was during the transition of a couple of React Native applications to Kotlin Multiplatform. First, it was a pretty difficult process for me to get the project running using all of the scripts and the expo, second, the code for those projects was written pretty badly, they were using JavaScript and not TypeScript, so overall, it just didn’t feel right to me writing that for iOS and Android apps.
Then at some point, I started reading about Kotlin Multiplatform and the main benefits of the framework, when compared to the previously mentioned cross-platform frameworks:
That was enough for me to become super interested in KMM, and then slowly to pass on the hype to the rest of my time, and fast forward 6 months after I first heard of KMM, we currently manage 3 client projects that have written by using KMM.
That’s the list of companies that are already adopting Kotlin Multiplatform.
You heard that right! I was pretty curious when I found out about this, and I wanted to see how our way of doing Kotlin Multiplatform compares to how these big companies are doing it.
At McDonald’s, the main motivation was reducing the total amount of the code they needed to maintain. Also, one big advantage of KMP they are talking about is having the business logic isolated and unit-tested in one place. They are taking the integration slow, and migrating piece by piece of shared functionality to KMP.
Netflix, on the other hand, has been using it in their app built from scratch Prodicle which they are making to innovate in the area of physical production of TV shows and movies. They emphasize how the communication with the database and support for the offline mode is in one place.
When it comes to 9gag, the interesting thing is that they migrated the whole app to React Native in 2016, but as it grew, they had performance issues so they switched back to native. Then in 2020 when Flutter was gaining a lot of traction, they tried using it but eventually stepped away from it because of a lack of support for ads and Firebase, at least at the time. Then, they decided to give KMP a shot and started integrating it and they suggested starting with sharing some constants, then moving to writing some common utils in KMP, and just after that writing the whole business logic in the shared module. They are using it for network calls, offline mode, sharing resources with moko-resources, and encryption decryption.
Couple of weeks ago, Google announced they are using Kotlin Multiplatform for their Google Docs iOS and Android app. It’s a big proof that they mean serious with KMP and that KMP is here to stay.
As I stated previously, when using Kotlin Multiplatform, you get to decide which pieces of the business logic you want to place in the shared module and share them between your iOS and Android app.
There are two approaches you can go with in terms of the shared code:
We decided to go with the second approach because we want to take as much advantage as we can from KMM. We went through all of the available articles about the sharing view model in KMM and got started. It was way more difficult than we expected.
We spent a couple of days figuring out how to make it work and here are the challenges we faced:
But what a wonderful feeling it was in the end when we made it work. This is the complete tech stack that we are using across all three of our KMM projects right now:
Over time, as we saw that we could successfully ship applications using KMM, we got more comfortable trying out different approaches to sharing our view models between the apps:
We will keep exploring and pushing boundaries side by side with KMM!
My advice regarding KMP for now is if you want to start quickly, go with the first approach from the above and share only the data layer.
But if your goal is to share as much code as you can in the long run, I would advise you to go with a second approach as we did. More work in the beginning, but will bring more benefits later on in the product development lifecycle. These are the main benefits we had when working with KMM:
Kotlin Multiplatform is just heating up, it’s going to be huge.
iOS engineers from all over the world found these e-books and project templates as the ultimate source of knowledge needed to build and scale their mobile apps