Mastering Kotlin Multiplatform

The short answer

Kotlin Multiplatform (formerly KMM) is a technology allowing developers to share common business logic written in Kotlin across various platforms like Android, iOS, web, and desktop. It enables code reuse for parts of an application while maintaining the flexibility to build platform-specific user interfaces and integrate with native capabilities, for instance, sharing a data fetching module between an Android and an iOS app.

This lesson explains Kotlin Multiplatform (formerly KMM), a technology for sharing code across different platforms. You will understand its core principles, how it fundamentally works, and what it truly enables for modern software development.

By BasicsTutor · Created with AI, researched and fact-checked · Updated Nov 29, 2026 · How we make lessons

Technology·advanced·12 min

Software Requires Specific Execution Environments

Every piece of software, fundamentally a set of instructions written as source code, must be translated and executed within a specific operating environment, or platform. These platforms—like Android, iOS, Windows, or a web browser—each possess unique processor architectures, operating system services (APIs), memory management rules, and build requirements. For example, a program compiled for an ARM-based iOS device cannot directly run on an x86-based Windows machine because their underlying hardware and software interfaces are fundamentally different. This is true because computers don't natively understand high-level programming languages; they execute low-level machine code or bytecode interpreted by a runtime. Each platform provides its own set of tools and conventions for converting source code into this executable form and managing its operation. Without a compatible environment, source code is inert; it is merely a blueprint without a workshop or specialized tools to realize its function. A common misconception is that once code is written, it is universally portable and will simply "work" everywhere. People often assume that software is a self-contained entity, independent of its host. However, a program is more akin to a visitor in a foreign country; it needs to speak the local language and understand local customs to function. Simply writing the instructions doesn't make them universally understood or executable. The non-obvious implication here is that true code reuse across diverse platforms is not about ignoring these fundamental differences, but about strategically acknowledging and managing them. It reframes multiplatform development not as a way to circumvent platform specifics, but as an advanced technique for orchestrating how common logic interacts with distinct environments.

Imagine you're writing a recipe. Each cooking appliance (oven, microwave, slow cooker) is a 'platform' with unique operating temperatures, methods, and features. Your recipe (source code) needs to be adapted: a cake for the oven won't work in a microwave without significant changes. The 'recipe book' for each appliance (its runtime and APIs) defines what's possible. Shared ingredients are like shared logic, but the cooking process must be specific to the appliance.

  • Software needs a specific platform to run.
  • Platforms have unique hardware, OS, and APIs.
  • Code doesn't automatically adapt to all platforms.

Effective Code Sharing Requires Defined Boundaries for Platform-Specifics

Because every platform is unique (Principle 1), to share code effectively, developers must explicitly establish clear boundaries between universal, portable logic and code that must be customized for each specific platform's environment. This separation allows the common business rules, data processing, or algorithms to be written once, while interactions with platform-specific features—like user interfaces, hardware sensors, or native libraries—are handled by dedicated implementations for each target. Kotlin Multiplatform achieves this by structuring projects with "shared source sets" for generic logic and "platform-specific source sets" (e.g., `androidMain`, `iosMain`) for tailored implementations. A core mechanism is the `expect`/`actual` declaration: a shared `expect` declaration defines a capability or interface in the common code, acting as a contract. Each platform-specific source set then provides an `actual` implementation that fulfills this contract using its native APIs or features. This proves the principle by demonstrating that sharing is not a blind fusion, but a deliberate architectural separation. Many wrongly believe that "sharing code" means sharing everything, and that the shared code will magically adapt to any platform's quirks without explicit intervention. This intuition fails because it neglects the fundamental differences between environments. Without explicit boundaries, attempts at sharing would quickly run into conflicts, as common code would try to invoke non-existent platform-specific features, or platform code would try to understand generic concepts without a defined interface. The non-obvious implication is that the true power of multiplatform development lies not in eliminating platform-specific code, but in minimizing, centralizing, and explicitly managing it. Developers are not just writing shared logic; they are designing a sophisticated architectural contract, carefully deciding where the universal ends and the highly specialized begins. This requires a deeper understanding of both the shared domain and the distinct target platforms.

Consider a global company designing a new product. The core engineering (shared logic) is handled by one central team. However, each regional office (platform) then customizes the packaging, marketing, and distribution channels (platform-specific implementations) to suit local laws and consumer preferences. The 'contract' is the product specification document (`expect`), and the localized versions are the specific implementations (`actual`).

  • Separate universal logic from platform-specific code.
  • Kotlin Multiplatform uses shared and platform-specific source sets.
  • `expect`/`actual` defines common capabilities and their platform implementations.

Shared Logic Does Not Necessitate a Shared User Interface

The decision to share an application's core logic, such as data handling, business rules, or complex algorithms, is fundamentally independent of the decision to share its user interface (UI). These are distinct architectural choices. Kotlin Multiplatform explicitly supports sharing backend logic while allowing developers to implement UIs using each platform's native frameworks, such as Jetpack Compose on Android and UIKit/SwiftUI on iOS. This principle holds because while application logic deals with what the application does, the UI deals with how users interact with it and how information is presented. Each platform has highly optimized, idiomatic UI frameworks designed to provide the best possible user experience and performance within its ecosystem. Attempting to force a single UI across diverse platforms often results in a 'lowest common denominator' experience that feels out of place or performs poorly on some targets, rather than leveraging their native strengths. A common, yet mistaken, belief is that "multiplatform" or "cross-platform" always implies a single UI that looks and behaves identically everywhere. Many assume that if you adopt KMP, you are automatically committing to a shared UI technology like Compose Multiplatform, or that KMP itself handles UI rendering. This intuition fails because it conflates the underlying data and logic with its visual presentation, which are separate layers of an application. The genuinely counterintuitive implication is that the most effective multiplatform strategies often prioritize native-feeling user experiences. By decoupling shared logic from the UI, developers can deliver highly performant, idiomatic applications that resonate with users on each platform, while still gaining significant development efficiency from code reuse. It shifts the goal from achieving 'identical apps' to 'consistently behaving, native-feeling apps' across different platforms.

Think of a restaurant chain. The core recipes and ingredients (shared logic) are standardized across all locations. However, the dining room decor, table settings, and even the menu design (UI) are customized for each country or region to suit local tastes and culture, using local materials and designers (native UI frameworks). The food is consistent, but the experience is localized.

  • Sharing logic is separate from sharing UI.
  • Native UIs provide optimal platform-specific user experience.
  • KMP allows native UI, or shared UI via other tools (e.g., Compose Multiplatform).

Multiplatform Development is an Orchestration of Platform-Specific Builds

Building a multiplatform application is not a single, universal compilation process, but rather an orchestration of multiple, distinct compilation workflows, each precisely tailored to generate runnable artifacts for a specific target platform. This means that while shared code is written once, the process of turning it into an executable component for Android, iOS, or other targets involves unique steps for each. This derives directly from Principle 1. The Kotlin toolchain, at its heart, acts as a sophisticated conductor. For Android, it compiles the shared Kotlin code into JVM bytecode and packages it alongside Android-specific code. For iOS, it uses Kotlin/Native to compile the shared Kotlin code into native binaries (like a `.framework` or `.xcframework`) that Xcode can then link with Swift/Objective-C code. Each target generates its own self-contained artifact, adhering to that platform's packaging and execution standards. This is evident in the configuration of build scripts, which define separate targets and their respective dependencies and compilation flags. A common misconception is that multiplatform development involves a single "magic button" that automatically spits out ready-to-use versions of the app for every platform, or that it somehow bypasses the need for traditional, platform-specific build steps. This intuition fails because it misunderstands the fundamental role of compilers and linkers, which are inherently platform-specific tools, transforming source code into instructions that only a particular type of processor and operating system can understand. The non-obvious implication is that true mastery of Kotlin Multiplatform extends beyond merely writing shared code; it encompasses a deep understanding and skillful management of the build system. Developers must grasp the nuances of how each target platform consumes the shared code, how dependencies are managed across targets, and how to integrate effectively with existing platform build tools. The efficiency gain is in writing less new logic, not in simplifying the final delivery mechanism for each target.

Imagine a music composer who writes a score for an orchestra (shared code). While the melody and harmony are consistent, the conductor (Kotlin toolchain) needs to manage different sections (strings, brass, percussion) and ensure each musician (platform-specific compiler/linker) plays their part correctly, creating a complete symphony (final application) for the audience (target platform). Each section's sheet music is 'compiled' for their instrument.

  • KMP builds involve distinct compilations for each target.
  • Kotlin/JVM compiles for Android, Kotlin/Native for iOS.
  • Mastering KMP requires understanding the build system and toolchain.

Platform Nuances Persist and Require Conscious Management

Even with significant advancements in code sharing, fundamental differences between platforms regarding their operating system behavior, API availability, ecosystem tools, and user expectations persist. These nuances are not eliminated by multiplatform solutions like Kotlin Multiplatform; they simply shift the focus of where and how these differences are managed. This principle builds on all preceding ones: each platform remains a unique environment (Principle 1) that requires explicit handling for specific features (Principle 2) and distinct build processes (Principle 4). For example, memory management patterns might differ between JVM and native environments, specific hardware sensors could have varying levels of support or different APIs, and even seemingly universal concepts like file system access or network connectivity can have platform-specific error codes or permission models. Thorough testing on each target platform remains critical to ensure correct behavior and a high-quality user experience. A common misconception is that once core logic is shared, the majority of development challenges simply disappear, and that the remaining platform-specific work is minimal or trivial. This intuition fails because it underestimates the depth and breadth of differences between sophisticated modern operating systems, ignoring the constant evolution of platform-specific features and user interaction paradigms. The non-obvious implication is that successful Kotlin Multiplatform projects still demand engineers with strong platform-specific knowledge. While KMP consolidates business logic development, it requires developers to anticipate and solve integration challenges, optimize for native performance and idioms, and ensure that the application feels genuinely native on each platform. Multiplatform development is not a magic bullet that removes complexity; rather, it's a strategic trade-off that relocates and reframes complexity, allowing teams to gain efficiency in one area by carefully managing intricacies in others.

Consider designing a house (the app) with a common floor plan (shared logic). While the layout is consistent, the local building codes, available construction materials, climate considerations, and aesthetic preferences (platform nuances) for each region where the house is built will significantly affect the final design, requiring local architects and contractors (platform-specific developers) to adapt it. You can't just copy-paste the building permits.

  • Platforms retain unique behaviors and APIs despite code sharing.
  • Memory management, hardware access, and OS interaction vary.
  • Platform-specific expertise and testing remain vital for success.

Put it into practice

  • Visit the official JetBrains Kotlin Multiplatform documentation website. Focus specifically on the 'Get Started' guides to set up a simple shared module between Android and iOS, familiarizing yourself with source set structure and build configuration.
  • Create a small, experimental Kotlin Multiplatform project. Implement a utility function or an interface for accessing platform-specific information (e.g., getting the device name or current time zone) using the `expect`/`actual` mechanism to understand how shared code interacts with platform-specific implementations.
  • Find an open-source Kotlin Multiplatform project on GitHub or GitLab. Clone it and spend an hour examining its `build.gradle.kts` files, `commonMain`, `androidMain`, and `iosMain` source sets to observe how code separation and platform targeting are practically implemented in a real-world scenario.
  • Identify a specific, non-UI module in an existing or planned mobile application (e.g., data validation, network request serialization/deserialization, or a complex calculation) that could benefit from being shared between Android and iOS. Sketch out how you would design this module using KMP's shared logic approach, noting where `expect`/`actual` might be needed and how dependencies would be managed.

Sources

  1. Mastering Cross-Platform Development with Kotlin Multiplatform ... · 2024-07-29
  2. Mastering KMM: How Kotlin Compiles for Android and iOS...
  3. Kotlin Multiplatform (KMP): The Ultimate Guide (2026) · 2026-02-08
  4. softwarepatternslexicon.com › kotlin › kotlin-in-theKotlin Multiplatform Mobile (KMM): Sharing Code Between iOS ... · 2024-11-17
  5. Kotlin Multiplatform Mobile (KMM): The Complete Developer Guide · 2025-08-11
  6. Kotlin Multiplatform(KMP) Masterclass - KMM - GitHub · 2024-01-17
  7. Kmm · 2025-04-29
  8. Kotlin Multiplatform Mobile

Keep learning

Browse all lessons