Kotlin Multiplatform, a solution created by JetBrains to enable the use of Kotlin to share native code across different platforms, is now stable and ready for production use, says JetBrains engineer Ekaterina Petrova.
Initially released in 2022 as a beta, Kotlin Multiplatform allows developers to create applications that run natively on each supported platform. Having reached stability, the solution now features a stable API that will evolve following compatibility rules, simplified project configuration, and better interoperability with Objective-C and Swift. In addition, says Petrova, it brings faster build times and other performance improvements.
Kotlin Multiplatform is made of multiple components that provide integration with existing compilers, support for language features, libraries API, IDEs, tooling, and more. While most of them are now stable, there are several features available in the current release that are still experimental, such as expect/actual classes, and will keep evolving.
Since KMP uses the Kotlin Gradle plugin, it benefits from improvements introduced in the last version of the plugin, including support for hierarchical project layouts and less boilerplate. Additionally, the plugin improves diagnostics thanks to 50 new warnings/errors which aim to help identify common build issues.
Regarding build and runtime performance, Kotlin Multiplatform now supports Gradle configuration cache to reuse configuration artifacts in successive builds; benefits from the new custom memory allocator introduced in Kotlin 1.9 and from the experimental incremental compilation of klib
artifacts.
Thanks to all of these advancements, Kotlin Multiplatform can be used without hesitation for sharing code in production across Android, iOS, desktop (JVM), server-Side (JVM), and web, even in the most conservative usage scenarios.
Thanks to another technology from JetBrains, Compose Multiplatform, developers can adopt different strategies for code sharing across platforms, specifically regarding the split between business logic and UI.
Indeed, an application could use Kotlin Multiplatform just for a few shared components implementing parts of the business logic, while the UI is built using platform-specific frameworks; or use Kotlin Multiplatform in combination with Compose Multiplatform to ideally achieve a fully cross-platform codebase.
Compose Multiplatform for Android and desktop (JVM) is already stable, while support for iOS is currently in alpha and support for web through Wasm is still experimental.