This episode explores Kotlin Multiplatform: the KMP architecture with a shared module for JVM, Android, JS, and Native, expect and actual declarations, a source set hierarchy for sharing code across platforms, and real-world use cases for mobile, desktop, and web.

Kotlin doesn't only run on the JVM and Android. Episode 12 opens up Kotlin Multiplatform (KMP): the ability to write business logic once and use it on Android, iOS, desktop, JavaScript, and Native. This is JetBrains' strategic direction and one of the fastest-growing topics.
The key to KMP is dividing code into platform-common code that is shared and platform-specific code written per target. expect and actual declarations bridge the two with compile-time guarantees.
After this episode, you'll understand when KMP is the right fit and how to structure your first shared module.
KMP lets you write a shared module once and compile it to several targets: JVM, Android, iOS (Native), JavaScript (Wasm), and desktop. Platform-common code contains business logic, data models, and data connections; platform-specific code contains APIs that depend on the operating system.
This hierarchy is configured in the Gradle file. An example of target configuration:
kotlin {
jvm()
androidTarget()
iosX64()
iosArm64()
iosSimulatorArm64()
js(IR) {
browser()
nodejs()
}
sourceSets {
commonMain.dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
}
}
}jvm() for desktop/server, androidTarget() for Android, the three ios* variants for Apple devices and simulators, and js(IR) for the web. Shared dependencies are declared in commonMain.
Code for iOS and Native is compiled into native binaries (not JVM bytecode) using the Kotlin/Native compiler. This means iOS apps run Kotlin code compiled directly to machine code, with full native performance.
The main KMP source sets are commonMain for shared code and commonTest for shared tests. Each target has its own source set, such as androidMain and iosMain, for platform-specific code. The KMP compiler creates intermediate source sets (like nativeMain) automatically based on the declared targets.
The logic that benefits most from sharing:
UI code usually stays platform-specific — Compose Multiplatform for desktop and Android, SwiftUI for iOS. Sharing logic and separating UI is the most common KMP pattern in production.
The expect keyword declares an API that every platform must provide. The actual keyword provides its platform-specific implementation. A classic example: getting the current date:
expect fun tanggalSekarang(): StringThe declaration expect fun tanggalSekarang() states a contract: every platform must provide this function. The compiler guarantees every expect declaration has a matching actual on every target — if one is missing, the build fails.
Each target provides its own implementation:
actual fun tanggalSekarang(): String = java.time.LocalDate.now().toString()Other targets contain their own actual versions in their source sets. The expect-actual pattern is the bridge that keeps types safe across platforms — no fragile runtime reflection, only implementations verified at compile time.
Common KMP usage patterns:
Teams using KMP report major savings because business rules are written once and tested once for all platforms.
KMP adds complexity to builds and tooling. For quick prototypes or purely single-platform apps, a plain Kotlin JVM or Android project is simpler. Consider KMP when you genuinely target several platforms with significant business logic.
Episode 12 opened up Kotlin Multiplatform: the shared module architecture for JVM, Android, JS, and Native, the source set hierarchy for sharing code, expect and actual declarations guaranteed by the compiler, and use cases for mobile, desktop, and web.
The key takeaways:
expect declares an API; actual provides the per-platform implementation.In episode 13 we'll discuss testing and quality — unit testing with Kotlin Test, JUnit, and Kotest, mocking with MockK or Mockito, Behavior-Driven Testing patterns, and continuous testing and automation that keep code quality high.