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

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
ParameterMeaning
android, ios, desktop, web, servertrue includes that target; a target left out is off
iosuicompose shares the UI with Compose Multiplatform (the default)
webuicompose shares the UI on web too; the alternative is React with TypeScript, chosen in the page
includeTeststrue or false
buildSystemkotlin 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 setCompiled for
commonMainevery target you declare
iosMain, appleMain, nativeMainintermediate sets created by the default hierarchy template (iOS, Apple, all native targets)
androidMain, jvmMain, jsMain, wasmJsMainone 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:

NeedLibrary
Asynckotlinx.coroutines
JSONkotlinx.serialization
Date and timekotlinx-datetime
HTTPKtor client (an engine per platform: OkHttp on Android, Darwin on iOS)
DatabaseSQLDelight
Key-value settingsmultiplatform-settings
Dependency injectionKoin
ImagesCoil 3
LoggingKermit
I/OOkio, kotlinx-io
Navigation and componentsDecompose, Voyager
Platform UI and APIs from ComposeCalf
StarterKaMP 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

SymptomCauseFix
Gradle error after moving to AGP 9KMP plugin cannot be combined with com.android.application or com.android.libraryMove the Android entry point to androidApp, use the Android-KMP library plugin in shared
Unresolved reference to java.io.File in common codeJDK classes do not exist on native targetsUse a multiplatform library (kotlinx-io, Okio) or expect/actual
actual is flagged as missing or mismatchedDifferent package, signature, or no actual for one targetSame package and signature, one actual per platform source set
Library types missing in SwiftDependency not exported from the iOS frameworkAdd export(...) to the framework block
iOS build fails in Xcode onlyStale framework or missing toolchainRun kdoctor, clean the build, rerun the Gradle embed task
Code placed in iosArm64Main but not seen by the simulatorTarget-specific source setPut shared iOS code in iosMain

Quick Reference

ItemValue
Shared codesrc/commonMain/kotlin
Declare targetskotlin { jvm(); iosArm64(); iosSimulatorArm64() }
Android target (AGP 9)kotlin { android { namespace = "..."; compileSdk = ...; minSdk = ... } }
Platform APIexpect fun x() in common, actual fun x() per platform, same package
All tests./gradlew allTests
iOS tests./gradlew iosSimulatorArm64Test
Check the environmentkdoctor

See Also