Overview
Kotlin Multiplatform (KMP) shares Kotlin code between Android, iOS, desktop, web and server, while each platform keeps its own native entry point and can still call platform APIs. You share as much as makes sense (networking, data, business logic, optionally UI with Compose Multiplatform) and write the rest natively.
Platform stability (core KMP): Android, iOS, Desktop (JVM), Server-side (JVM) and Web on Kotlin/JS are Stable. Web on Kotlin/Wasm, watchOS and tvOS are Beta. Source: stability of supported platforms; Kotlin/Wasm is Stable in Kotlin 2.5, so check that page for the current status.
Setup
Start a project kmp.jetbrains.com (Kotlin Multiplatform Wizard; links can be prefilled, see below), or the KMP plugin in Android Studio / IntelliJ IDEA
Check your Mac brew install kdoctor && kdoctor (finds missing Xcode, JDK, Android SDK pieces)
iOS builds need a Mac with Xcode
Libraries klibs.io: AI-powered search over 5,100+ KMP libraries (JetBrains, open source)
# Run the shared tests on every target your machine can build
./gradlew allTests
./gradlew jvmTest
./gradlew iosSimulatorArm64Test
Prefilled Wizard Links
The wizard reads its choices from the URL, so you can bookmark or share a starting point:
https://kmp.jetbrains.com/?android=true&ios=true&iosui=compose&includeTests=true
| Parameter | Meaning |
|---|---|
android, ios, desktop, web, server | true includes that target; a target left out is off |
iosui | compose shares the UI with Compose Multiplatform (the default) |
webui | compose shares the UI on web too; the alternative is React with TypeScript, chosen in the page |
includeTests | true or false |
buildSystem | kotlin selects the Kotlin Toolchain; leave it out for Gradle |
With no parameters you get Android and iOS, shared Compose UI and tests. Checked against the live wizard on 2026-12-05. Picking “Do not share UI - Use SwiftUI” writes iosui=swiftui into the address bar, but loading that value back showed the Compose option selected, so make that choice in the page.
Project Structure
my-app/
├── shared/ Kotlin code shared by all platforms (KMP library module)
│ └── src/
│ ├── commonMain/ code for every target (no platform APIs)
│ ├── commonTest/ tests for common code
│ ├── androidMain/ Android-only code
│ ├── iosMain/ code shared by all iOS targets
│ └── jvmMain/ desktop or server code
├── androidApp/ Android entry point (its own module)
├── iosApp/ Xcode project: SwiftUI shell that uses the shared framework
└── desktopApp/ optional desktop entry point
| Source set | Compiled for |
|---|---|
commonMain | every target you declare |
iosMain, appleMain, nativeMain | intermediate sets created by the default hierarchy template (iOS, Apple, all native targets) |
androidMain, jvmMain, jsMain, wasmJsMain | one target each |
Common code can only use Kotlin and multiplatform libraries. The compiler rejects java.io.File or any other JDK class there, because the same code also compiles to native.
Gradle Setup
With Android Gradle Plugin 9.0 or newer, the KMP plugin no longer works together with com.android.application or com.android.library. Put the Android app in its own module (androidApp) and use the Android-KMP library plugin in the shared module.
// shared/build.gradle.kts
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.android.kotlin.multiplatform.library) // id: com.android.kotlin.multiplatform.library
}
kotlin {
android {
namespace = "com.example.shared"
compileSdk = 36 // Compose Multiplatform 1.13 needs 37.1; see the CMP page
minSdk = 24
}
jvm() // desktop or server
iosArm64()
iosSimulatorArm64()
// iOS framework that the Xcode project imports
listOf(iosArm64(), iosSimulatorArm64()).forEach {
it.binaries.framework {
baseName = "Shared"
isStatic = true
}
}
sourceSets {
commonMain.dependencies {
implementation(libs.kotlinx.coroutines.core)
}
commonTest.dependencies {
implementation(kotlin("test"))
}
}
}
# gradle/libs.versions.toml (from the Android KMP plugin docs)
[plugins]
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
android-kotlin-multiplatform-library = { id = "com.android.kotlin.multiplatform.library", version.ref = "androidGradlePlugin" }
Until you migrate you can keep the old setup with android.enableLegacyVariantApi=true in gradle.properties, but those APIs are removed in AGP 10. Guide: updating to AGP 9.
Platform APIs: expect / actual
Declare the API in common code, implement it per platform. Rules: the actual sits in the same package, expect declarations have no implementation, and every platform source set needs an actual.
// commonMain
package identity
class Identity(val userName: String, val processID: Long)
expect fun buildIdentity(): Identity
// jvmMain
package identity
import java.lang.System
import java.lang.ProcessHandle
actual fun buildIdentity() = Identity(System.getProperty("user.name") ?: "none", ProcessHandle.current().pid())
// nativeMain (iOS and other native targets)
package identity
import kotlinx.cinterop.toKString
import platform.posix.getlogin
import platform.posix.getpid
actual fun buildIdentity() = Identity(getlogin()?.toKString() ?: "none", getpid().toLong())
Often an interface plus dependency injection is cleaner than expect/actual:
// commonMain
interface Platform { val name: String }
class Greeting(private val platform: Platform) { fun greet() = "Hello from ${platform.name}" }
// androidMain: class AndroidPlatform : Platform { override val name = "Android ${android.os.Build.VERSION.SDK_INT}" }
// iosMain: class IosPlatform : Platform { override val name = platform.UIKit.UIDevice.currentDevice.systemName() }
Docs: expected and actual declarations, use platform-specific APIs.
iOS
Xcode build phase runs the Gradle task embedAndSignAppleFrameworkForXcode
Framework baseName and isStatic are set in the iOS binaries block (see Gradle Setup)
Swift from Kotlin Kotlin types appear to Swift through Objective-C; Swift export is Beta (Kotlin 2.5)
Swift packages SwiftPM import is Beta: use SDKs such as Firebase or Google Maps from KMP
Nicer Swift API SKIE (Touchlab) improves how Kotlin flows, sealed classes and enums look in Swift
Exported libraries a library whose types you expose to Swift must be exported: export("group:artifact:version") in the framework block
Libraries
Search klibs.io first: JetBrains’ AI-powered search for Kotlin Multiplatform libraries (5,100+ projects), open source at JetBrains/klibs-io, with an FAQ. A community Claude Code skill, Wavesonics/klibs-skill, searches it from a plain-language description. The usual picks:
| Need | Library |
|---|---|
| Async | kotlinx.coroutines |
| JSON | kotlinx.serialization |
| Date and time | kotlinx-datetime |
| HTTP | Ktor client (an engine per platform: OkHttp on Android, Darwin on iOS) |
| Database | SQLDelight |
| Key-value settings | multiplatform-settings |
| Dependency injection | Koin |
| Images | Coil 3 |
| Logging | Kermit |
| I/O | Okio, kotlinx-io |
| Navigation and components | Decompose, Voyager |
| Platform UI and APIs from Compose | Calf |
| Starter | KaMP Kit (Touchlab) |
Publishing a Library
Kotlin 2.5 adds an experimental publication format that packs platform artifacts into one .kar archive, which keeps multi-target libraries under Maven Central size limits: set kotlin.publicationFormat=KOTLIN_ARCHIVE in gradle.properties. Consuming such artifacts already works for every project.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Gradle error after moving to AGP 9 | KMP plugin cannot be combined with com.android.application or com.android.library | Move the Android entry point to androidApp, use the Android-KMP library plugin in shared |
Unresolved reference to java.io.File in common code | JDK classes do not exist on native targets | Use a multiplatform library (kotlinx-io, Okio) or expect/actual |
actual is flagged as missing or mismatched | Different package, signature, or no actual for one target | Same package and signature, one actual per platform source set |
| Library types missing in Swift | Dependency not exported from the iOS framework | Add export(...) to the framework block |
| iOS build fails in Xcode only | Stale framework or missing toolchain | Run kdoctor, clean the build, rerun the Gradle embed task |
Code placed in iosArm64Main but not seen by the simulator | Target-specific source set | Put shared iOS code in iosMain |
Quick Reference
| Item | Value |
|---|---|
| Shared code | src/commonMain/kotlin |
| Declare targets | kotlin { jvm(); iosArm64(); iosSimulatorArm64() } |
| Android target (AGP 9) | kotlin { android { namespace = "..."; compileSdk = ...; minSdk = ... } } |
| Platform API | expect fun x() in common, actual fun x() per platform, same package |
| All tests | ./gradlew allTests |
| iOS tests | ./gradlew iosSimulatorArm64Test |
| Check the environment | kdoctor |
See Also
- Kotlin Multiplatform documentation
- Project structure basics and hierarchy
- Android Gradle library plugin for KMP
- KMP Wizard, klibs.io (library search, source), KDoctor
- Compose Multiplatform - shared UI on top of KMP
- Kotlin - language reference and what is new in 2.3 to 2.5