The Kotlin Multiplatform technology is designed to simplify the development of cross-platform projects. It reduces time spent writing and maintaining the same code for different platforms while retaining the flexibility and benefits of native programming.
Kotlin Multiplatform use cases
Android and iOS applications
Sharing code between mobile platforms is a major Kotlin Multiplatform use cases. With Kotlin Multiplatform for mobile, you can build cross-platform mobile applications that share code between Android and iOS to implement networking, data storage and data validation, analytics, computations, and other application logic.
Check out the Get started with Kotlin Multiplatform for mobile and Create a multiplatform app using Ktor and SQLDelight tutorials, where you will create applications for Android and iOS that include a module with shared code for both platforms.
Thanks to Compose Multiplatform, a Kotlin-based declarative UI framework developed by JetBrains, you can also share UIs across Android and iOS to create fully cross-platform apps:
Try this Compose Multiplatform mobile application template to create your own mobile application with UIs shared between both platforms.
Kotlin Multiplatform is also helpful for library authors. You can create a multiplatform library with common code and its platform-specific implementations for JVM, web, and native platforms. Once published, a multiplatform library can be used as a dependency in other cross-platform projects.
See the Create and publish a multiplatform library tutorial, where you will create a multiplatform library, test it, and publish it to Maven.
Compose Multiplatform helps share UIs across desktop platforms like Windows, macOS, and Linux. Many applications, including the JetBrains Toolbox app, have already adopted this approach.
Try this Compose Multiplatform desktop application template to create your own project with UIs shared among desktop platforms.
Code sharing between platforms
Kotlin Multiplatform allows you to maintain a single codebase of the application logic for different platforms. You also get advantages of native programming, including great performance and full access to platform SDKs.
Kotlin provides the following code sharing mechanisms:
Begin with the Get started with Kotlin Multiplatform for mobile if you want to create iOS and Android applications with shared code
Explore sharing code principles and examples if you want to create applications or libraries targeting other platforms
Look through cross-platform application samples to understand how Kotlin Multiplatform works: