· 4 min read Posted by Russell Wolf
The Evolution of Kotlin Multiplatform Mobile - 2022 Edition (OLD)
Kotlin Multiplatform has come a long way in the last few years. As someone who was there when the KMP community first formed, I’ve seen the ecosystem grow from a few developers trying things out experimentally to a growing number of teams using it in their production apps. With the Kotlin Multiplatform Mobile Beta freshly announced, it’s a neat moment to look back on how far everything has come.
How It Started
In the early days, KMP wasn’t very easy for new users. There were many technical limitations on how code could be written compared to traditionally writing Kotlin on Android or the JVM. The strict Kotlin/Native memory model was a common pain-point, limiting how developers could write multithreaded code. The Gradle setup was complicated and constantly changing. The Xcode integration was minimal and relied on handwritten gradle tasks to run tests or package a framework that the iOS project could use.
How It’s Going
Today, things look very different. The new Kotlin/Native memory manager includes a garbage collector that behaves similar to the JVM, making it easier to handle threading in common code. The development flow of exposing Kotlin to Xcode has improved considerably, and it’s now possible to integrate your Kotlin code via Cocoapods or Swift Package Manager so that it behaves more like a native iOS dependency. The API surface that Kotlin exposes to Swift has also steadily improved, including some cross-language generics support (initially implemented by Kevin Galligan of Touchlab). Kotlin Multiplatform Mobile has emerged as the killer app of the KMP ecosystem and is the KMP use-case that JetBrains is focused on supporting and fully stabilizing first.
A Brief History of the KMM ecosystem
Back in the summer of 2018, there were about five published libraries between Jetbrains and the community. This included my own Multiplatform Settings as well as SqlDelight, which was powered on iOS by a Touchlab-designed engine. Today, there are over 1000 library artifacts on Maven Central that target both iOS and Android or the JVM. There are now multiple competing libraries in a number of use-cases, including logging, storage, and architecture. We’re even starting to see larger SDK vendors include Kotlin Multiplatform as part of their offering, including companies like Realm and Sentry. More and more people have bought into this ecosystem, making it more likely that there are libraries available to suit your needs, whatever they are.
KaMP Kit’s Early Role in KMM
A few years ago, getting started in Kotlin Multiplatform was difficult because the tooling was iterating quickly. Most documentation became out-of-date shortly after it was written.
To help address this, in 2020 Touchlab released KaMP Kit, a demo project configured to run out-of-the-box along with up-to-date documentation to get new KMP developers started. In 2022, the overall ecosystem of starter projects and templates is much larger. If you’re learning how to write multiplatform code and looking to get a new project up-and-running, there’s plenty of resources and KaMP Kit remains a good option.
Moving Forward With Teams
One thing that the community still lacks is resources and support around integration with existing apps in production. Most templates and samples implicitly assume you’re starting a new project with a monorepo setup, which makes configuration easier but isn’t realistic if you’re trying to integrate KMM into your pre-existing native app.
This is where we’ve been focusing our recent efforts at Touchlab. When adding shared code to an existing build process (or two, in most cases), new issues come up that aren’t always apparent in a brand new application, such as managing communication between multiple teams and multiple repositories. We have developed tooling to make it easier to package and publish your Kotlin code and ship it to wherever you already consume dependencies from. To learn more about this tooling, check out our introduction to KMMBridge here, before trying it for yourself with this template project and tutorial. We’re also working on tools to improve the Swift/Kotlin language boundary, so that the APIs that Kotlin exposes look more natural to native Swift developers.
What’s Next?
It’s a great time to be investing in Kotlin Multiplatform Mobile. Whether you’re just trying it as an experiment, using it in a new greenfield app, or integrating it into your existing native apps, Touchlab is here to help. You can join our community on the Kotlinlang Slack at #touchlab-tools, or if you’re ready to explore how Touchlab can help you grow as KMM developers, contact us here.