At Google I/O 2024, Google announced its collaboration with JetBrains and the Kotlin community to advance the Kotlin Multiplatform (KMP) ecosystem. This initiative aims to provide mobile developers with enhanced productivity by leveraging KMP's capabilities.
Google is transitioning its applications to KMP to enable code sharing across different platforms. A notable example is the Google Docs app, which now shares business logic across Android, iOS and the web application.
In addition, Google is also migrating its libraries to KMP. Notable examples include Room and Datastore, along with Compose, which facilitates the sharing of UI code across various platforms.
As of 2024, if you are not familiar with KMP, here's a brief overview:
KMP is a technology that facilitates code sharing across multiple platforms.
Shared Kotlin code compiles into platform-specific binaries, integrating seamlessly into any project. This technology allows developers to utilize platform-specific APIs, eliminating the need to choose between native and cross-platform development. KMP offers the best of both worlds.
Which platforms are supported? Examples include JavaScript, JVM (such as Android), macOS, iOS, watchOS, tvOS, Linux, and more.
While this can seem too good to be true, it is far from being an experimental technology : Netflix, one the companies with the highest reliability standards, has been using it massively for some time already. Many others use KMP, see few examples below.
Versatility
Kotlin Multiplatform (KMP) offers a broad range of applications across various platforms:
Flexibility
KMP provides significant flexibility in how developers can share and manage their code:
Kotlin-to-Objective-C on iOS
Currently, Kotlin code for iOS is compiled into Objective-C, which limits interoperability with Swift. Ongoing development on direct Kotlin-to-Swift compilation will make Kotlin code more seamlessly integrated into Swift projects.
Lack of Precise Documentation
KMP has a steep learning curve, which is exacerbated by the lack of detailed technical documentation. Although JetBrains and the community are continually expanding the available resources, including tutorials, example projects and project creation wizards, more comprehensive guides and examples are still needed to assist new developers.
WebAssembly (WASM) Support in Alpha
While KMP provides stable support for many platforms, WebAssembly (WASM) support is still in alpha. This is a crucial area of development, particularly because WASM will be essential for projects like Compose Multiplatform to operate effectively in web environments. Ongoing efforts are being made to stabilize WASM support and address current limitations.
KMP is Multiplatform but Not Cross-Platform
KMP facilitates significant code sharing but does not inherently provide a cross-platform UI solution. By default, developers need to create platform-specific UIs using native technologies like SwiftUI for iOS and Compose for Android. However, if a unified UI approach is desired across platforms, Compose Multiplatform (CMP) can be used on top of KMP to provide consistent UI across different environments.
Compose Multiplatform (CMP) extends the capabilities of KMP by providing a unified UI framework across various platforms. It builds on the stability and flexibility of KMP, allowing developers to create consistent UIs using a single codebase. CMP uses SKIA for rendering on non-Android platforms, offering a performance level comparable to Flutter.
Unified UI Across Platforms
CMP allows developers to create a consistent UI across multiple platforms using a single codebase. This greatly simplifies the development process for applications that need to look and feel the same on different devices. It builds on the stability and flexibility provided by KMP.
Seamless Performance Across Platforms
On Android, CMP leverages Jetpack Compose directly, providing truly native performance. For platforms other than Android, including iOS, desktop, and web, CMP uses SKIA for rendering. Although SKIA is not a native renderer, it is highly optimized and provides excellent performance, ensuring a smooth and responsive user experience across these platforms. This approach is comparable to Flutter and offers high performance, albeit not at the native level on non-Android platforms.
The Stability of CMP
On Android, CMP is native so it is stable. On desktop, CMP is also stable. Recently, CMP for iOS has moved from alpha to beta, as announced at the Kotlin Conf. For the web, CMP has progressed from experimental to alpha. While still in its early stages, especially for web development, CMP shows great promise. It is currently suitable for use on iOS, but for web applications, it might still be a bit early, though the prospects are very promising.
SEO and Accessibility Concerns
Using CMP for web applications introduces challenges related to SEO and accessibility. Since CMP renders within a canvas outside the DOM, it can hinder search engine optimization and accessibility compliance. CMP has recently moved to alpha, indicating that these issues will likely be addressed in future updates. In the meantime, alternatives like Compose HTML and enhancements from tools like Kobweb provide more immediate solutions for SEO-friendly and accessible web development.
Performance Considerations Across Platforms
While CMP provides high performance across different platforms, there are specific considerations for each:
Flutter is increasingly popular within the mobile development community. Despite Google's announcement at Google I/O 2024 about its focus on Kotlin Multiplatform (KMP), this did not stop them from hosting numerous conferences and codelabs on Flutter. No, Flutter is not dead: I encourage you to read our CTO's article on this topic.
So, will Flutter hinder the rise of KMP? We don't believe so. The KMP community is indeed growing steadily, and Flutter's popularity does not impede this growth. Over the past year, Flutter and React Native have coexisted without one hindering the other's development. In contrast, older technologies like Cordova and Xamarin are losing market share, and the number of fully native applications is also declining.
Google announcing its efforts on KMP opens a number of opportunities for the Kotlin ecosystem. More and more Kotlin libraries have opened to other platforms - or at least are actively doing so, including big names such as Ktor, Coil, Room or Koin. It will enable Android Developers to start migrating most of their code to KMP modules as soon as compatible versions are made available.
KMP relies heavily on seamless interoperability with other languages, and Swift was notably missing from the list of compatible languages. There is currently an Objective-C binding between them, making harder to have an interface that cover all Swift features. It was only a matter of time for a Kotlin-to-Swift integration to be announced: it will be a lot easier to use Kotlin code in Swift and vice-versa. JetBrains’ roadmap makes it a clear priority so we can expect it to be a reality soon.
When it comes to UI, Compose Multiplatform has recently updated its iOS and Web support to beta and alpha, respectively. We can reasonably expect to be able to develop production-ready universal apps in full KMP in the near future, starting with mobile and desktop. It is already possible to leverage Android Studio’s multiplatform plugins but JetBrains’ multi-language IDE Fleet looks promising.
All in all, when you have big native codebases, sharing business logic is critical: it speeds up delivery while freeing more time for tech teams to increase code quality and make a positive impact on your product.
At BAM, we believe this is a perfect opportunity to start migrating your app’s business logic!
Dennis Bordet
Nicolas Acart
Hugo Duprat