What you'll learn
What if you could write your business logic once and run it on Android, iOS, the JVM backend, the web, and native desktop? That's Kotlin Multiplatform (KMP) — share the code that's the same everywhere, and write platform-specific code only where it truly differs.
By the end you'll be able to:
- Explain the Kotlin Multiplatform concept and source sets
- Use
expect/actualto bridge platform differences - Name the main compilation targets
- Understand Kotlin/Native and when KMP pays off
The KMP concept
KMP splits your code into source sets. commonMain holds shared, pure-Kotlin logic — models, validation, networking, business rules — with no platform dependencies. Platform source sets (androidMain, iosMain, jvmMain, jsMain) hold the bits that must differ. You typically share the logic and keep each platform's UI native:
Key idea
expect / actual
When shared code needs something a platform provides differently — the device name, secure storage, the current time zone — you declare an expect in commonMain (the contract) and supply an actual in each platform source set (the implementation). It's the same idea as an interface, but resolved at compile time per target:
// commonMain — shared code declares WHAT it needs, not how
expect fun platformName(): String
fun greeting(): String = "Hello from ${platformName()}"// androidMain — the Android-specific implementation
actual fun platformName(): String = "Android ${android.os.Build.VERSION.SDK_INT}"// iosMain — the iOS-specific implementation
import platform.UIKit.UIDevice
actual fun platformName(): String = UIDevice.currentDevice.systemName()Shared code calls greeting() without knowing or caring which platform it runs on — the right actual is linked in for each target.
Targeting platforms
Kotlin compiles the same source to very different runtimes:
- Kotlin/JVM — Android and server-side (bytecode)
- Kotlin/Native — iOS, macOS, Linux, Windows (native binaries, no JVM)
- Kotlin/JS — the browser and Node.js (JavaScript)
- Kotlin/Wasm — WebAssembly, an emerging high-performance web target
Kotlin/Native
Kotlin/Native compiles Kotlin straight to a native binary using the LLVM toolchain — no JVM required. It's what makes iOS support possible: your shared Kotlin becomes a framework Swift code can call. It also enables standalone native executables for desktop and embedded use. Memory is managed by a garbage collector, so it feels like ordinary Kotlin.
When it's worth it
KMP shines when you maintain the same app or logic on multiple platforms and want a single source of truth for business rules — fewer bugs, no duplicated logic drifting apart. For a single-platform app, the extra setup usually isn't worth it. As always, choose the tool that fits the problem.
Note
Recap & quick check
Key takeaways
- Kotlin Multiplatform shares common code across platforms while keeping platform-specific parts separate.
- commonMain holds shared logic; androidMain/iosMain/etc. hold platform-specific implementations.
- expect declares a contract in common code; actual provides each platform's implementation.
- Kotlin targets the JVM, Native (LLVM, no JVM), JS, and Wasm from one language.
- KMP pays off for multi-platform apps that want one source of truth; it's overkill for single-platform ones.
Quick check
1. What lives in the commonMain source set?
2. What do expect and actual do together?
3. What makes Kotlin/Native special?
4. What does KMP typically encourage sharing vs. keeping native?
5. When is KMP probably NOT worth the effort?
You've seen how far Kotlin reaches. To finish Phase 7, we'll pull it all together with the habits of a professional: clean code, idioms, and a real development workflow.