Technologies Natives

Just as Google, BAM believes in Kotlin Multiplatform

Google Unveils Bold Strategy to Boost Kotlin Multiplatform Ecosystem Development

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.

Kotlin Multiplatform in a Nutshell

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.

Kotlin Multiplatform (KMP)

Advantages of KMP

Versatility

Kotlin Multiplatform (KMP) offers a broad range of applications across various platforms:

  1. Code Sharing Across Platforms: KMP allows developers to share code across iOS, Android, desktop, backend and web applications. This significantly reduces development time and effort, enabling a more efficient workflow. KMP is stable on Android and desktop platforms, provides solid support for iOS with compilation to Objective-C (with ongoing efforts to compile directly to Swift for better integration), and supports stable JavaScript transpilation for web applications. WebAssembly (WASM) support is currently in alpha but is gradually stabilizing, especially since it's essential for Compose Multiplatform.
  2. Unified Business Logic (Consistency): By sharing business logic, KMP ensures consistency across different platforms while maintaining native performance. This is particularly beneficial for applications requiring a consistent user experience and functionality across multiple devices.
  3. Backend Development: KMP is not limited to frontend development; it is also highly effective for backend services. This makes it a comprehensive solution for full-stack development, providing a unified approach to handling both frontend and backend logic.

Flexibility

KMP provides significant flexibility in how developers can share and manage their code:

  1. Granular Code Sharing: KMP allows developers to share as much or as little code as needed between platforms. Developers can choose to share specific functions, modules, or the entire application logic, providing a high degree of customization and flexibility.
  2. Diverse UI Options: KMP focuses on sharing business logic across platforms. Developers who write the core of their app in KMP still retain the freedom to choose how they implement the UI. They can either use a native framework on each platform to provide a more familiar experience to users or unify every step of their workflow with Compose Multiplatform.
  3. Native Performance: KMP ensures that shared logic operates at a native level, providing the same speed and responsiveness as applications developed directly for each platform.

Limitations of KMP

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.

Unified UI with Compose Multiplatform (CMP)

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.

Advantages of Compose Multiplatform (CMP)

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.

Limitations of Compose Multiplatform (CMP)

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:

  • Android: CMP uses Jetpack Compose, offering native performance.
  • iOS, Desktop, and Web: CMP uses SKIA for rendering. Although SKIA is not a native rendering solution, it provides very high performance, comparable to native solutions, and ensures a consistent and smooth user experience across these platforms.
  • Web (Kotlin/JS): CMP can compile to Kotlin/JS, which offers broad compatibility and good performance for most web applications. It ensures that applications can run efficiently on various browsers.
  • Web (Kotlin/WASM): For higher performance, especially for more complex applications, CMP supports Kotlin/WASM. However, Kotlin/WASM requires modern browser support, including garbage collection capabilities, which are currently limited to the latest versions of Chrome and Firefox and are not yet supported by Safari.

KMP in the Shadow of Flutter or KMP Overshadowing Flutter?

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.

The Future of KMP: What To Expect?

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.

A Perfect Opportunity To Take Action

At BAM, we believe this is a perfect opportunity to start migrating your app’s business logic!

  • If you want to build a product from scratch with fully native technologies, we can assist you in developing your business logic in KMP and create native UIs with Jetpack Compose and SwiftUI. This approach will provide a solid foundation to migrate to a complete Compose codebase in the future.
  • Our expertise in developing universal apps will help you identify which parts of your codebase are already ready for KMP, then migrate more and more of it as the Kotlin community releases compatible versions of the libraries you are using.
  • Jetpack Compose is now the go-to UI framework for Android apps, and aims for more with Compose Multiplatform! We can help you plan and execute a migration from the legacy XML user interfaces. We also can provide training for your in-house Android developers.
  • Compose Multiplatform still is in beta, so we think SwiftUI is the better choice for your iOS app. With Kotlin-to-Swift coming soon, this is the time to migrate from UIKit. We can help your tech team manage a smooth migration without compromising on quality.

Authors

Dennis Bordet
Nicolas Acart
Hugo Duprat

Développeur mobile ?

Rejoins nos équipes