Kotlin Multiplatform
|
This content was generated with the assistance of AI and should be verified against the official Kotlin Multiplatform documentation before being relied on in production. See the section bibliography for the reference material consulted while preparing these pages. |
Welcome to the Kotlin Multiplatform reference. Kotlin Multiplatform (KMP) is JetBrains' technology for compiling one Kotlin codebase to several platforms — JVM and Android, native iOS and macOS binaries, JavaScript and WebAssembly — while still letting each platform keep its own code where it matters. You decide how much to share: only the business logic (networking, storage, domain rules and view models) behind fully native UIs written in Jetpack Compose and SwiftUI, or the user interface as well with Compose Multiplatform (CMP), JetBrains' port of Jetpack Compose to Android, iOS, desktop and the web. Both paths are documented in full here, on top of the same project.
This section targets Kotlin 2.4.20 and Compose Multiplatform 1.12.1 (based on Jetpack Compose 1.12.1), the Android
Gradle Plugin 9.4 with its com.android.kotlin.multiplatform.library plugin, and Xcode 26.4, the version Kotlin 2.4.20
is tested against. Every page names the exact library versions it uses — Ktor 3.6.0, SQLDelight 2.4.0, Koin 4.2.2,
Room 3 (androidx.room3) 3.0.3, SKIE 0.10.15, KMP-NativeCoroutines 1.0.6, Mokkery 3.5.0 and the rest — and states
the stability level of every API that is not Stable. In particular, Swift export and SwiftPM import are Alpha,
and Kotlin/Wasm and Compose Multiplatform for web are Beta, while Android, iOS, desktop and Kotlin/JS targets are
Stable.
This section does not re-teach the Kotlin language, Jetpack Compose basics or SwiftUI basics — it links to them. The Kotlin language lives in the Kotlin Reference. The sibling sections are Android (native Android and Jetpack Compose), Apple Platforms (Swift, SwiftUI, Xcode and the App Store) and React Native (the TypeScript cross-platform alternative). The multi-platform projects page of the Apple section describes Apple’s own multi-platform targets and is unrelated to Kotlin Multiplatform.
How Kotlin Multiplatform got here
| Year | What changed |
|---|---|
2017—2018 |
Kotlin/Native entered preview and Kotlin gained multiplatform projects, sharing code between the JVM, JavaScript
and native targets through |
2020 |
Kotlin Multiplatform Mobile (KMM) reached Alpha: Android and iOS apps sharing a Kotlin module, with a dedicated IDE plugin. |
2021 |
Compose for Desktop and Compose for Web appeared as previews, the first steps toward sharing UI code beyond Android. |
2022 |
The new Kotlin/Native memory manager (default since Kotlin 1.7.20) removed the object-freezing restrictions that had made concurrent iOS code awkward. |
2023 |
Kotlin Multiplatform became Stable with Kotlin 1.9.20, together with the default hierarchy template. |
2024 |
Google announced official support for Kotlin Multiplatform for shared business logic on Android, and Jetpack libraries (ViewModel, Room, DataStore, Paging) began to ship multiplatform artifacts. Kotlin 2.0 made the K2 compiler the default. |
2025 |
Compose Multiplatform for iOS became Stable. Kotlin/Wasm and Compose Multiplatform for web reached Beta. |
2026 |
The |
New here? Read in this order
Pick the path that matches your goal. The numbered lists follow the order of the pages in the navigation.
Share logic, keep native UI — the path for teams that want SwiftUI on iOS and Jetpack Compose on Android:
Share the UI with Compose Multiplatform — one UI for Android, iOS, desktop and the web:
Add KMP to an existing app — migrate an Android app, or add a shared module to an iOS app, step by step:
The TrailMate Everywhere project
Every code example is a slice of one project: the Android section’s TrailMate hiking-trail app (package
com.example.trailmate) made multiplatform, so pages can link to the Android equivalents instead of repeating them.
-
Modules —
sharedLogic(domain, data and view models),sharedUI(the Compose MultiplatformTrailListScreen,TrailDetailScreen,SettingsScreen,App()andTrailMateTheme),androidApp,iosApp(an Xcode project with a SwiftUI version and a Compose MultiplatformMainViewControllerversion),desktopAppandwebApp(wasmJs). -
Domain and data —
Trail(id, name, region, lengthKm, difficulty, photoUrl, isFavorite),enum class Difficulty,TrailPhoto; the remote API athttps://api.example.com/v1/through the KtorTrailApiClientandTrailDto; a SQLDelightTrailMateDatabasewith Room 3 as the alternative; a DataStoreUserPreferencesRepository; theTrailRepositoryinterface implemented byOfflineFirstTrailRepository;expect/actualplatformName()andcurrentTimeZone(); and theLocationProviderinterface withAndroidLocationProviderandIosLocationProvider. -
Presentation —
TrailListViewModelandTrailDetailViewModelexposingStateFlow<TrailListUiState>, wired through the Koin moduletrailMateModule. -
Two UI paths — native UI (a SwiftUI
TrailListViewobserving the shared view model through SKIE or KMP-NativeCoroutines, and Jetpack Compose on Android) and shared UI (Compose Multiplatform everywhere, with anMKMapViewembedded on iOS). -
Tests —
OfflineFirstTrailRepositoryTest,FakeTrailApiClient(KtorMockEngine),TrailListViewModelTest(Turbine) andTrailListScreenTest(runComposeUiTest). -
Library example — the publishing and CI pages use a small library,
com.example:trail-geo(geodesic distance and elevation-profile helpers), published to Maven Central and as an XCFramework through SwiftPM.
What’s covered
Foundations
-
What Kotlin Multiplatform Is and When to Use It — what KMP and Compose Multiplatform are, the economics of native, cross-platform and multiplatform development, the two sharing paths, and when to choose which.
-
How KMP Compiles: Kotlin/JVM, Kotlin/Native, Kotlin/JS and Kotlin/Wasm — the Kotlin/JVM, Kotlin/Native, Kotlin/JS and Kotlin/Wasm compilers, the supported targets, and the Kotlin/Native target tiers.
-
Getting Started: IDEs, the KMP Plugin and Your First Project — IntelliJ IDEA and Android Studio with the Kotlin Multiplatform plugin, the web wizard, and your first TrailMate Everywhere project.
-
Project Structure, Targets, Source Sets and the Hierarchy Template — targets, source sets, the default hierarchy template and the recommended
sharedLogic/sharedUI/androidApplayout. -
Gradle Configuration, the Multiplatform DSL and Compatibility — the
kotlin {}multiplatform DSL, version catalogs, compiler options and the Kotlin/Gradle/AGP/Xcode compatibility matrix. -
The Android Target: the Android-KMP Library Plugin and AGP 9 — the
com.android.kotlin.multiplatform.libraryplugin, the separateandroidAppmodule and the AGP 9 migration. -
expect/actual and Calling Platform APIs —
expect/actualdeclarations versus interfaces and dependency injection, and calling platform APIs. -
Dependencies, klibs.io, cinterop and SwiftPM Import — adding multiplatform dependencies, klibs.io, cinterop, KSP per target and SwiftPM import.
Sharing business logic
-
Kotlin for Swift Developers — a Swift-to-Kotlin concept mapping for iOS developers: optionals, value types, extensions, async/await versus coroutines.
-
Coroutines, Flow and Concurrency in Shared Code — coroutines,
Flow,StateFlowand dispatchers on every platform, and Kotlin/Native concurrency. -
Architecture, Shared ViewModels and State — layered architecture, shared
ViewModel`s, `StateFlowUI state and one-off events. -
Networking with the Ktor Client — the Ktor client with per-platform engines, content negotiation, auth, retries, timeouts and testing.
-
Local Storage: SQLDelight, Room, SQLite Drivers, DataStore and Settings — SQLDelight, Room 3, SQLite drivers, DataStore and multiplatform-settings, with the offline-first repository.
-
Dependency Injection in KMP: Koin, Metro and Manual DI — Koin, Metro, kotlin-inject and manual DI in shared code.
-
Essential Multiplatform Libraries — kotlinx libraries, logging, image loading, Firebase, settings and other libraries that work in
commonMain.
iOS integration and interop
-
Integrating Shared Code into iOS: Direct, SwiftPM and CocoaPods — direct integration, SwiftPM export and import, CocoaPods and XCFrameworks.
-
Objective-C Interop, Swift Export and SKIE — how Kotlin maps to Objective-C and Swift, SKIE, and Swift export (Alpha).
-
Consuming Coroutines and Flow from Swift and SwiftUI — consuming
suspendfunctions andFlowfrom Swift and SwiftUI with SKIE, KMP-NativeCoroutines and Swift export. -
Kotlin/Native Memory, Performance, Binary Size and Debugging — the memory manager and GC, performance and binary size, binary options and debugging.
Sharing UI with Compose Multiplatform
-
Compose Multiplatform Fundamentals — what Compose Multiplatform is, setup, entry points on each platform, and the shared
sharedUImodule. -
Resources and Localization in Compose Multiplatform — the resources library, qualifiers, strings, plurals, fonts, localization and the resource environment.
-
Lifecycle, ViewModel and Navigation in Compose Multiplatform — lifecycle,
ViewModel, Navigation Compose, Navigation 3 and deep links on every platform. -
Layouts, Material 3, Adaptive UI, Popups and Accessibility — layouts, Material 3, adaptive UI with window size classes, popups, RTL and accessibility.
-
Compose Multiplatform on iOS: UIKit and SwiftUI Interop — embedding UIKit and SwiftUI in Compose and Compose in SwiftUI, touch, Liquid Glass and iOS accessibility.
-
Compose Multiplatform for Desktop — windows, menus, tray, keyboard and mouse, Swing interop and native distribution.
-
Web Targets: Kotlin/Wasm, Kotlin/JS and Compose for Web — Kotlin/Wasm and Kotlin/JS targets, Compose for Web, JS interop and web resources.
Quality, shipping and adoption
-
Testing Multiplatform Code —
kotlin-test, fakes versus mocks, Mokkery, Turbine, KtorMockEngine, Compose UI tests and coverage. -
Publishing Multiplatform Libraries (Maven Central, SwiftPM, npm) — publishing to Maven Central, SwiftPM and npm, Dokka and binary compatibility validation.
-
Publishing KMP Apps to Google Play, the App Store, Desktop and the Web — shipping to Google Play, the App Store, desktop installers and the web.
-
CI/CD for KMP with GitHub Actions — building, testing and publishing KMP projects with GitHub Actions and macOS runners.
-
Adopting KMP in Existing Android and iOS Apps — migrating existing Android and iOS apps, monorepo versus multi-repo, and team structure.
Reference
-
Kotlin Multiplatform Cheat Sheet — a one-page printable A4 summary of the whole section, also downloadable as a PDF.
Book and official sources compared
One book was read locally against the concepts documented here, purely to decide what to cover and to check for gaps — it is not quoted or copied into this repository, and no other page of this section cites it. The official documentation is the primary source for every page.
| # | Book | Publisher / year / ISBN | Publisher page |
|---|---|---|---|
B1 |
Róbert Nagy, Simplifying Application Development with Kotlin Multiplatform Mobile: Write robust native applications for iOS and Android efficiently |
Packt, March 2022, ISBN 978-1-80181-258-0 |
The book’s example app, Dogify (Dog API, Ktor, SQLDelight, Koin, Jetpack Compose on Android and SwiftUI with Combine on iOS), matches the "share logic only" path documented in pages 9 to 19.
Concept by book matrix
A check mark means the topic has a chapter or a main section, a half mark means partial coverage or an older API, and a dash means it is not covered. The page numbers are the position of the page in the navigation.
| Concept group (pages) | Official | B1 (chapter) |
|---|---|---|
Native vs cross-platform vs multiplatform; use cases (1) |
✔ |
✔ (Ch 1) |
The Kotlin compilers: JVM, Native, JS, Wasm (2) |
✔ |
◐ (Ch 2; no Wasm, JS as ES5 only) |
Tooling, IDE, wizard (3) |
✔ |
◐ (Ch 4; Android Studio Arctic Fox, KMM plugin, AppCode) |
Project structure, source sets, hierarchy (4) |
✔ |
◐ (Ch 2 Commonizer, Ch 5; |
Gradle DSL, version catalogs, compatibility (5) |
✔ |
◐ (Ch 3 Gradle intro; |
Android target and AGP 9 (6) |
✔ |
— |
expect/actual and platform APIs (7) |
✔ |
✔ (Ch 1, 5) |
Dependencies, klibs.io, cinterop, SwiftPM import (8) |
✔ |
◐ (CocoaPods only) |
Kotlin for Swift developers (9) |
◐ |
✔ (Ch 3) |
Coroutines, Flow and concurrency (10) |
✔ |
◐ (Ch 3, 8; |
Architecture and shared ViewModels (11) |
✔ |
◐ (Ch 4, 8; no Jetpack ViewModel KMP) |
Networking with Ktor (12) |
✔ |
◐ (Ch 5; Ktor 1.x) |
Local storage: SQLDelight, Room, DataStore (13) |
✔ |
◐ (Ch 5; SQLDelight 1.x only) |
Dependency injection (14) |
◐ |
◐ (Koin 3.1 used; Kodein mentioned) |
Essential multiplatform libraries (15) |
✔ |
◐ (kotlinx.serialization; moko-resources mentioned) |
iOS integration options (16) |
✔ |
◐ (Ch 7, 9; embedAndSign, CocoaPods, XCFramework, SPM mentioned) |
Objective-C/Swift interop and Swift export (17) |
✔ |
◐ (Ch 2, 8; "direct Swift interop" as future work) |
Coroutines and Flow from Swift (18) |
✔ |
✔ (Ch 7; KMP-NativeCoroutines with Combine) |
Kotlin/Native memory, performance and binary size (19) |
✔ |
◐ (Ch 2, 8; old model, app size) |
Compose Multiplatform fundamentals (20) |
✔ |
— (Ch 10 lists "shared UI" as future work) |
CMP resources (21) |
✔ |
◐ (moko-resources mentioned) |
CMP navigation and lifecycle (22) |
✔ |
— |
CMP UI, Material 3, adaptive, accessibility (23) |
✔ |
— |
CMP on iOS: UIKit/SwiftUI interop (24) |
✔ |
— |
CMP desktop (25) |
✔ |
— |
Web: Kotlin/Wasm and Kotlin/JS (26) |
✔ |
◐ (Ch 2; Kotlin/JS only) |
Testing (27) |
✔ |
◐ (Ch 8; |
Publishing libraries (28) |
✔ |
◐ (Ch 9; XCFramework, CocoaPods/Carthage/SPM) |
Publishing apps (29) |
✔ |
— |
CI/CD with GitHub Actions (30) |
✔ |
— |
Adopting KMP: monorepo vs multi-repo, teams (31) |
✔ |
✔ (Ch 9) |
Concepts found mostly in the book
Each of these is folded into an existing page; none gets a page of its own.
| Concept | Where it is covered |
|---|---|
The economics of native, cross-platform and multiplatform development: synchronization cost, and the assumed versus actual cost of cross-platform |
|
A Swift to Kotlin concept mapping (optionals, structs versus data classes, copy-on-write, extensions, async/await versus coroutines, Combine versus Flow) |
|
DTOs at the Swift boundary, and exposing callbacks from shared view models |
Architecture, Shared ViewModels and State and Objective-C Interop, Swift Export and SKIE |
Binary size of the Objective-C header, and limiting the exported API |
Objective-C Interop, Swift Export and SKIE and Kotlin/Native Memory, Performance, Binary Size and Debugging |
Fakes over mocks on Kotlin/Native |
|
Mono repository versus multiple repositories, team structure and adoption tips |
Official concepts missing from the book
These are documented from the official sources only: Compose Multiplatform on every platform (resources, navigation
including Navigation 3, lifecycle and ViewModel, UIKit and SwiftUI interop, desktop and web); Compose Hot Reload;
the default hierarchy template and the androidApp/sharedLogic/sharedUI layout; the AGP 9 Android-KMP plugin;
the Jetpack KMP libraries (ViewModel, Room 3, DataStore, SQLite drivers, Paging); Swift export, SwiftPM import, the
CocoaPods to SwiftPM migration and SKIE; the new memory manager and the CMS garbage collector; Kotlin/Wasm; target
tiers and Apple minimum OS versions; klibs.io; ABI validation in the Kotlin Gradle plugin; Dokka 2; the Maven Central
Portal with the vanniktech plugin; the App Store privacy manifest; GitHub Actions and TeamCity CI; the Kotlin Toolchain
(formerly Amper); and the K2 compiler.
Outdated book material
These techniques appear in the section only as legacy, each next to its modern replacement.
| Legacy technique (book, 2022) | Modern replacement |
|---|---|
"KMM" naming, the KMM Android Studio plugin, AppCode |
"KMP"; the Kotlin Multiplatform IDE plugin for IntelliJ IDEA and Android Studio (AppCode is discontinued) |
|
Explicit |
Manual |
The default hierarchy template (Kotlin 1.9.20) |
Legacy memory model, |
The new memory manager (default in 1.7.20; the legacy one was removed in 1.9.20) and plain kotlinx-coroutines |
|
Version catalogs ( |
|
|
Ktor 1.x ( |
Ktor 3.x ( |
SQLDelight 1.x ( |
SQLDelight 2.x ( |
Koin 3.1 |
Koin 4.2 ( |
Fat or universal frameworks, bitcode |
XCFrameworks (bitcode is unsupported since Kotlin 2.0.20) |
CocoaPods-first iOS integration |
Direct integration ( |
"Direct Swift interop" as a future plan |
Swift export (Alpha) |
"Shared UI" as a future plan |
Compose Multiplatform (Stable on iOS) |
Kotlin/JS targeting ES5 |
Kotlin/JS with ES2015+ output, and Kotlin/Wasm |
kapt-style annotation processing on Native |
KSP ( |
Related sections
This section builds on material documented elsewhere on this site rather than repeating it. The Kotlin Reference covers the language every example is written in, including coroutines and flows. Android documents native Android, Jetpack Compose, Room, Ktor, Koin and Google Play — the TrailMate app that this section makes multiplatform. Apple Platforms covers Swift, SwiftUI, Xcode, Swift Package Manager, signing and the App Store for the iOS side. React Native is the cross-platform alternative that targets Android and iOS from one TypeScript codebase, and Git & GitHub underlies the version control and pull-request workflow assumed on the CI/CD page.
Bibliography
Kotlin Multiplatform documentation (kotlinlang.org)
Every kotlinlang.org/docs/multiplatform/ page cited on a concept page, grouped by topic. The official documentation is the primary source for every page and every code example.
Overview, getting started and learning
-
Kotlin docs — The basics of Kotlin Multiplatform project structure
-
Kotlin docs — Create a multiplatform app using Ktor and SQLDelight
-
Kotlin docs — Native and cross-platform app development: how to choose?
-
Kotlin docs — Create a Kotlin Multiplatform app (quickstart)
-
Kotlin docs — Kotlin and Compose Multiplatform in production: real-world use cases
Project structure, Gradle and compatibility
-
Kotlin docs — Adding dependencies on multiplatform libraries
-
Kotlin docs — Advanced concepts of the multiplatform project structure
-
Kotlin docs — Updating multiplatform projects with Android apps to use AGP 9
-
Kotlin docs — Choosing a configuration for your Kotlin Multiplatform project
-
Kotlin docs — Recommended Kotlin Multiplatform project structure
iOS integration, SwiftPM and CocoaPods
Kotlin/Native, Kotlin/Wasm, Kotlin/JS, Gradle and API guidelines
The kotlinlang.org/docs/ and API reference pages cited on the concept pages, including the Kotlin language pages the sections link to instead of re-teaching.
Compose Multiplatform
The Compose Multiplatform documentation pages, the product page and the GitHub releases and repository.
Fundamentals, setup and compatibility
Resources, localization and navigation
iOS, desktop and web
Android Developers
The developer.android.com pages cited on the concept pages: the /kotlin/multiplatform/* articles, AGP 9, and the Jetpack release notes.
-
Android Developers — Preview your UI with composable previews
-
Android Developers — Type safety in Kotlin DSL and Navigation Compose
-
Android Developers — Add KMP module to a project (plugin author guidance)
-
Android Developers — Migrate your existing app to Kotlin Multiplatform
-
Android Developers — Navigation event for Kotlin Multiplatform
-
Android Developers — Set up the Android Gradle library plugin for KMP
-
Android Developers — Set up your environment for Kotlin Multiplatform
Apple developer documentation
The Apple and Swift documentation cited on the iOS, interop and publishing pages.
-
Apple Developer — Acquiring crash reports and diagnostic logs
-
Apple Developer — Building your app to include debugging information
-
Apple Developer — Creating a multiplatform binary framework bundle
-
Apple Developer — Distributing binary frameworks as Swift packages
-
Apple Developer — Distributing your app for beta testing and releases
Publishing and CI
Sonatype Central, vanniktech, Dokka, npm, Gradle, the GitHub Actions documentation and each action’s repository, and release tooling.
Book
-
Róbert Nagy, Simplifying Application Development with Kotlin Multiplatform Mobile: Write robust native applications for iOS and Android efficiently, Packt, March 2022, ISBN 978-1-80181-258-0 — Packt product page
-
Companion code — PacktPublishing/Simplifying-Application-Development-with-Kotlin-Multiplatform-Mobile