Kotlin Multiplatform seems to be the talk of the town recently, having seen a lot of notable companies embrace it despite it being in its early stage. Yes, it takes a lot of confidence and team power to be able to trust such a new and experimental feature, especially when it comes to integrating such into production apps. I’m lucky to work in a team where we have been using Kotlin multiplatform in production for quite a few months now and it’s been a journey; an absolutely fun one.
So, enough of the chit-chat, let’s get to business. What is Kotlin Multiplatform?
Kotlin Multiplatform is a language experimental feature that allows you to use a single codebase for the business logic of your iOS and Android apps, in pure kotlin. It reduces time spent writing and maintaining the same code for different platforms while retaining the flexibility and benefits of native programming. Kotlin multiplatform is not limited to iOS and Android, you get the benefit of sharing code with other platforms such as the JVM, JS and native Desktop. Although, I would be discussing more of Kotlin multiplatform mobile (KMM).
KMM has a fast-growing community and with plenty of supports from the Kotlin team and individuals around the world. This is very much demonstrated by how much people ask questions and discuss KMM in the Kotlin Slack workspace, bug report/feature request on YouTrack, kotlin-multiplatform questions on StackOverflow, as well as how there are so many Kotlin multiplatform libraries out there today.
Also, some of KMM’s early adopters are Netflix, Autodesk, CashApp, Careem to name but a few. You can find many more here, including how they use it in their mobile teams.
Having heard a lot about it and its benefits and potentials, KMM is something you might be willing to try out. “How do I get started with KMM?” is a very common question I see people ask and that I have been asked a few times. So here is my two cents about this.
Unlike most popular software engineering concepts, KMM as of today still lacks a lot of online resources. By online resources, I mean courses, articles, conference talks, problem solutions etc. This doesn’t necessarily mean you won’t find one or two resources on KMM online, you may just not find enough resources as you wish, especially when you run into some issues while using it. No one is really to be blamed for this, it’s still a pretty new feature and a lot of people are still experimenting with it while some are yet to. The more people use it, the more they can put out resources. Also, the more challenges people face and solve while using it, the more helpful resources you would find if you run into the same issues later on. I’m very hopeful that I would be able to put out some more helpful resources as time goes on as I continue learning as well.
Unlike most of my “getting started” articles, this article won’t specifically describe how to set up your development environment, create a new kotlin multiplatform project or do some other stuff. If I had done that, this article would have ended up being a dump of the whole Kotlin multiplatform documentation.
The KMM documentation is actually pretty cool and is a good and sufficient way to get started. It helped me get started and I believe it can help you as well. Here is how you can make good use of it.
The first section in the documentation describes how to get started with KMM. It describes how to set up your development environment for KMM development, a tutorial on how to create your first KMM application using the IDE wizard, a tutorial on how to make your application work on iOS, understanding the KMM project structure. Lastly, it has a guide on how to introduce your team to KMM. Pretty cool right? 😉
This section has some interesting topics which might not be of necessity to check before creating your first KMM application, but which you can find really beneficial as you progress on this journey. It has topics such as architecting your KMM application, adding dependencies to KMM modules, using SQLDelight for data storage, using Ktor for networking, and lots more.
This section has a curated list of KMM sample projects. Checking our existing projects helps you see possible use cases of KMM and what people have been able to pull off with it. There is also a belief that checking other people’s code can sometimes help one learn faster. Checking out some of these sample projects helped me and I believe it can help you too.
There are other sections in the documentation apart from the ones mentioned above but they might not be very important to start. I believe, those three sections above can get you started quickly and get you understanding the whole concept of KMM.
Refactoring Existing Project
Going through the documentation as described above would have gotten you at least a new project to practice with. Now that you understand KMM to some extent, you might want to work on getting comfortable with KMM. How about picking up an existing not-so-large project that probably has both Android and iOS and introducing a shared KMM module that enables both platforms to share common business logic? Sounds cool? This can actually help you get comfortable with bigger projects that probably has data storage, networking, etc rather than the simple project the IDE creates.
When you face a challenge, where do you go? That’s a question that you might be asking right now. Trust me, as lifesaving as StackOverflow is, I’ve run into KMM issues that didn’t have a solution on StackOverflow. Some have required me to check out GitHub issues, PRs and release notes of some APIs and libraries. As I said at the beginning of this article, KMM is still pretty new and it lacks a lot of helpful resources online. However, the community is growing, KMM channels on the Kotlin Slack workspace has been of help and is a place I would recommend joining. I have asked questions, I have seen people ask questions and I have seen people answer other people’s questions. It has been resourceful. I strongly recommend!
So yeah, you wanna try out Kotlin Multiplatform? Why not get started today? It’s worth it 😉. Also, feel free to reach out if you run into any issues. I’m still learning as well, so we can both troubleshoot issues together and learn in the process.