# Kotlin 多平台

**Kotlin 多平台**（Kotlin Multiplatform，KMP）是 [JetBrains](https://www.edgepedia.org/zh/jetbrains) 推出的一项开源技术，让开发者可以用 Kotlin 编程语言编写应用程序的某些部分，一次编写、编译到多个平台，包括 Android、iOS、JVM 桌面端与服务器端、Web 以及原生桌面端，同时将平台特定的代码和用户界面留给各平台自己的工具处理。该技术已经稳定并可用于生产环境，Google 官方支持用它跨移动端、Web、服务器端和桌面端共享业务逻辑。<sup>[1](https://developer.android.com/kotlin/multiplatform?authuser=13)</sup><sup> • </sup><sup>[2](https://blog.jetbrains.com/kotlin/2023/07/update-on-the-name-of-kotlin-multiplatform/)</sup>

| 关键事实 | 详情 |
|---|---|
| 首次发布 | 2017 年 KotlinConf 上以“Kotlin Multiplatform Projects”之名发布，支持 JVM、Native 和 JS 目标；直到 2020 年均为实验性<sup>[2](https://blog.jetbrains.com/kotlin/2023/07/update-on-the-name-of-kotlin-multiplatform/)</sup> |
| 命名 | “Kotlin Multiplatform Mobile”（KMM）作为产品名于 2023 年 7 月被弃用；KMP 成为所有目标组合的首选称谓<sup>[2](https://blog.jetbrains.com/kotlin/2023/07/update-on-the-name-of-kotlin-multiplatform/)</sup> |
| Google 支持 | 2024 年 5 月 14 日宣布 Android 正式支持 KMP，包括 Android Gradle 插件对 KMP 的支持<sup>[3](https://android-developers.googleblog.com/2024/05/android-support-for-kotlin-multiplatform-to-share-business-logic-across-mobile-web-server-desktop.html)</sup> |
| 共享 UI | iOS 版 Compose 多平台于 2025 年 5 月 6 日随 1.8.0 版本达到稳定版<sup>[4](https://blog.jetbrains.com/kotlin/2025/05/compose-multiplatform-1-8-0-released-compose-multiplatform-for-ios-is-stable-and-production-ready/)</sup> |
| 采用情况 | 超过 20,000 家公司使用；KMP 在使用跨平台框架的开发者中的份额从 7%（2024 年）升至 18%（2025 年）<sup>[5](https://kotlinlang.org/case-studies/)</sup><sup> • </sup><sup>[6](https://kotlinlang.org/state-of-kotlin-2026/)</sup> |
| 报告的收益 | Duolingo 从单一 KMP 代码库交付 iOS 和 Web 版本，节省了 6–12 个工程师月；Bitkey 共享了 95% 的移动端代码库<sup>[7](https://blog.jetbrains.com/kotlin/2026/04/helping-decision-makers-say-yes-to-kmp/)</sup> |

## 工作原理

一个 KMP 项目按源集（source set）组织，每个源集是一组 Kotlin 源文件，拥有自己的目标、依赖和编译器选项。预定义的 `commonMain` 源集存放所有已声明目标共享的代码；每个目标，如 `jvm`、`android` 或 `iosArm64`，都有对应的平台特定源集，如 `jvmMain` 或 `iosArm64Main`。中间源集可以在目标子集之间共享代码，例如为支持多线程的目标设置一个 `concurrent` 源集。<sup>[8](https://kotlinlang.org/docs/multiplatform/multiplatform-discover-project.html)</sup><sup> • </sup><sup>[9](https://kotlinlang.org/docs/api-guidelines-build-for-multiplatform.html)</sup>

`commonMain` 中的代码不能直接调用平台特定的 API，因为它要编译到每一个已声明的目标。平台特定源集可以使用平台依赖，例如 `jvmMain` 中仅限 Java 的库，并可以访问公共源集中的声明，但反过来则不行。当 Kotlin 为某个目标编译时，它会收集所有标记为该目标的源集，并一起从中生成二进制文件。<sup>[8](https://kotlinlang.org/docs/multiplatform/multiplatform-discover-project.html)</sup>

当公共 API 需要平台实现时，KMP 使用 `expect`/`actual` 声明：公共代码声明一个期望的函数或类，每个平台源集提供实际实现。文档中的标准示例是生成通用唯一标识符（UUID），每个平台用自己的机制实现。<sup>[10](https://kotlinlang.org/docs/multiplatform/multiplatform-connect-to-apis.html)</sup>

编译目标覆盖 Android、JVM、通过 Kotlin/Native 支持的 Apple 平台、[JavaScript](https://www.edgepedia.org/zh/javascript) 以及 [WebAssembly](https://www.edgepedia.org/zh/webassembly)；JetBrains 正在积极开发 Kotlin/Wasm 以支持现代 Web 开发。Kotlin/Native 通过 [Objective-C](https://www.edgepedia.org/zh/objective-c) 提供与 Swift 的互操作性，而较新的 Swift 导出功能旨在用干净的、模块特定的 Swift 导入取代 Objective-C 桥接层。<sup>[2](https://blog.jetbrains.com/kotlin/2023/07/update-on-the-name-of-kotlin-multiplatform/)</sup><sup> • </sup><sup>[11](https://kotlinlang.org/docs/native-overview.html)</sup><sup> • </sup><sup>[12](https://kotlinlang.org/docs/native-swift-export.html)</sup>

## 历史与命名

Kotlin 多平台于 2017 年 KotlinConf 上以“Kotlin Multiplatform Projects”之名发布，最初支持 JVM、Native 和 JS 目标。早期采用者将其缩写为“KMP”，较少使用“MPP”。该技术在 2020 年之前一直处于实验阶段，期间 JetBrains 根据早期采用者的反馈对其进行了塑造。

分裂的命名造成了持续的混乱，2023 年 7 月 JetBrains 弃用了 KMM 产品名，使“Kotlin 多平台”成为无论使用哪些目标时的首选称谓。<sup>[2](https://blog.jetbrains.com/kotlin/2023/07/update-on-the-name-of-kotlin-multiplatform/)</sup> Kotlin 多平台本身已变得稳定并可用于生产环境，2024 年 5 月的 Kotlin 2.0 搭载了从底层即为多平台设计的 K2 编译器，并对 Compose 多平台项目提供第一方支持。<sup>[13](https://blog.jetbrains.com/kotlin/2024/05/celebrating-kotlin-2-0-fast-smart-and-multiplatform/)</sup>

## Google 的背书与 Android 生态

2024 年 5 月 14 日，Google 宣布 Android 支持 Kotlin 多平台，以跨移动端、Web、服务器端和桌面端共享业务逻辑。Android Gradle 插件获得了官方 KMP 支持，库参考文档现在会标明哪些类和函数是“公共”的、哪些是平台特定的，Google 表示计划为更多 AndroidX 库添加 KMP 支持。<sup>[3](https://android-developers.googleblog.com/2024/05/android-support-for-kotlin-multiplatform-to-share-business-logic-across-mobile-web-server-desktop.html)</sup><sup> • </sup><sup>[14](https://android-developers.googleblog.com/2024/05/google-kotlinconf-2024-look-inside.html)</sup> Google 自身在 [Google Workspace](https://www.edgepedia.org/zh/google-workspace) 应用中使用了 KMP，并官方推荐用它共享业务逻辑。<sup>[13](https://blog.jetbrains.com/kotlin/2024/05/celebrating-kotlin-2-0-fast-smart-and-multiplatform/)</sup>

多个 Jetpack 库提供了 KMP 就绪版本，包括 Room、DataStore、ViewModel、Lifecycle、Navigation、Paging 和 Compose，各平台支持表已在 Android 文档中发布。<sup>[1](https://developer.android.com/kotlin/multiplatform?authuser=13)</sup><sup> • </sup><sup>[15](https://kotlinfoundation.org/kf_annual_report_2024.pdf)</sup> `com.android.kotlin.multiplatform.library` Gradle 插件是向 KMP 库模块添加 Android 目标的官方支持方式；较旧的 `com.android.library` 路径依赖的 API 已在 Android Gradle 插件 9.0 中弃用，预计将在 10.0 中移除。<sup>[16](https://developer.android.com/kotlin/multiplatform/plugin)</sup>

## Compose 多平台与共享 UI

最初几年，KMP 在 iOS 上的故事是“共享你的逻辑，原生构建你的 UI”。Compose 多平台是 JetBrains 基于 Android 的 [Jetpack Compose](https://www.edgepedia.org/zh/jetpack-compose) 构建的声明式 UI 框架，将共享扩展到 UI 层。2025 年 5 月 6 日发布的 1.8.0 版本使 iOS 版 Compose 达到稳定版，在热门用例上与 Jetpack Compose 功能对等，支持带深度链接的类型安全导航，以及包括 VoiceOver 在内的无障碍支持。<sup>[4](https://blog.jetbrains.com/kotlin/2025/05/compose-multiplatform-1-8-0-released-compose-multiplatform-for-ios-is-stable-and-production-ready/)</sup>

该框架还支持双向互操作：Compose 内容可以嵌入现有的 SwiftUI 或 UIKit 应用，原生视图也可以纳入 Compose 屏幕，从而支持渐进式采用。Respawn 的 iOS 应用就是用 Compose 多平台构建的，与 Android 共享了 96% 的代码。<sup>[4](https://blog.jetbrains.com/kotlin/2025/05/compose-multiplatform-1-8-0-released-compose-multiplatform-for-ios-is-stable-and-production-ready/)</sup> Web 版 Compose 多平台于 2025 年 9 月随 1.9.0 版本达到 Beta 阶段。<sup>[17](https://blog.jetbrains.com/kotlin/2025/09/compose-multiplatform-1-9-0-compose-for-web-beta/)</sup>

## 采用与生产使用

JetBrains 报告称，全球超过 20,000 家公司在金融、电子商务、社交媒体及其他领域使用 KMP。<sup>[5](https://kotlinlang.org/case-studies/)</sup> 在使用跨平台框架的开发者中，其份额一年内翻了一番多，从 2024 年的 7% 升至 2025 年的 18%，据 JetBrains 基于 Appfigures Intelligence 和 JetBrains 调查的《2026 年 Kotlin 现状》报告，它在 App Store 前 10,000 名应用中的增长速度快于 Flutter 和 [React Native](https://www.edgepedia.org/zh/react-native)。<sup>[6](https://kotlinlang.org/state-of-kotlin-2026/)</sup>

已发布的案例研究给出了具体数字。Duolingo 花了五个工程师月采用 KMP 并交付其 Adventures 功能的 iOS 版本，然后又花了一个半工程师月从同一代码库交付 Web 版本，而最初的 Android 实现用了九个月，总共节省了 6–12 个工程师月。<sup>[7](https://blog.jetbrains.com/kotlin/2026/04/helping-decision-makers-say-yes-to-kmp/)</sup> Bitkey 用 KMP 共享了 95% 的移动端代码库，[Blackstone](https://www.edgepedia.org/zh/blackstone) 报告称在整合代码后的六个月内实现速度提升了 50%，共享了约 90% 的业务逻辑。<sup>[7](https://blog.jetbrains.com/kotlin/2026/04/helping-decision-makers-say-yes-to-kmp/)</sup> [Physics Wallah](https://www.edgepedia.org/zh/physics-wallah) 应用在 [Google Play](https://www.edgepedia.org/zh/google-play) 上的下载量超过一千万次，其中约 20% 用 Kotlin 和 Compose 多平台构建，跨 Android 和 iOS 共享 UI 和业务逻辑。<sup>[5](https://kotlinlang.org/case-studies/)</sup> Cash App 于 2021 年采用 KMM，以移除有问题的共享 JavaScript，并让其 Android 和 iOS 工程师在保持各自首选工具链的同时维护单一代码库。<sup>[18](https://blog.jetbrains.com/kotlin/2021/03/cash-app-case-study/)</sup> 麦当劳于 2023 年开始在其 Global Mobile App 中使用 KMP，以渐进方式在孤立的部分（如网络和数据存储）中采用，而非彻底改造整个应用。<sup>[19](https://lambdadigamma.com/assets/publications/adopting-kotlin-multiplatform-in-the-future-lab-aachen-app.pdf)</sup>

## 与 Flutter 和 React Native 的比较

三大跨平台方案在语言、UI 方式和采用模式上各有不同。Flutter 使用 Dart 并通过 Skia 引擎渲染自己的 UI；React Native 使用 JavaScript 或 [TypeScript](https://www.edgepedia.org/zh/typescript) 并控制原生 UI 组件；KMP 使用 Kotlin，可以使用原生 UI 工具包（如 SwiftUI 和 Jetpack Compose），也可以通过 Compose 多平台使用共享 UI。共享的 Kotlin 代码在 Android 上编译为 JVM 字节码，在 iOS 上编译为原生二进制文件，运行时没有解释层。<sup>[20](https://www.infoq.com/articles/kotlin-multiplatform-evaluation/)</sup>

一个显著特性是渐进式采用。Flutter 和 React Native 都可以增量集成到现有的原生应用中，KMP 同样如此，可以渐进引入，通常先将单个功能或层迁移到共享模块中。<sup>[24](https://reactnative.dev/docs/next/integration-with-existing-apps)</sup> 这让团队可以随时间提升技能，并在过渡期间保持现有应用的稳定。<sup>[20](https://www.infoq.com/articles/kotlin-multiplatform-evaluation/)</sup> 对于已经使用 Kotlin 编程的 Android 团队来说，Google 对该语言的支持降低了入门门槛。<sup>[20](https://www.infoq.com/articles/kotlin-multiplatform-evaluation/)</sup>

实测性能部分支持了原生编译的说法。在一项使用 [ISO/IEC 25010](https://www.edgepedia.org/zh/iso-iec-25010) 比较同一植物管理应用五种实现的实证研究中，每种变体完成 2,000 次运行，原生在两个平台上都取得了最小的非 UI 客户端小计，而 Kotlin 多平台在跨平台方案中最接近，尽管操作和 UI 包装器的排名因任务而异。共享方案所编写的移动端源代码总量少于原生应用之和。<sup>[21](https://arxiv.org/abs/2609.21544)</sup>

## 局限性

实践者的报告指出了反复出现的摩擦。在现有代码库中为多平台项目设置 Gradle 颇具挑战，尤其是对 Gradle 经验有限的开发者而言，而为多个目标编译（尤其是面向 iOS 的 Kotlin/Native）相比单平台项目会增加构建时间。<sup>[19](https://lambdadigamma.com/assets/publications/adopting-kotlin-multiplatform-in-the-future-lab-aachen-app.pdf)</sup><sup> • </sup><sup>[22](https://www.ijtsrd.com/papers/ijtsrd50077.pdf)</sup> 访问原生 API 需要编写 `expect`/`actual` 声明或使用平台互操作机制。<sup>[22](https://www.ijtsrd.com/papers/ijtsrd50077.pdf)</sup> 与 Swift 的互操作历来通过 Objective-C 作为桥接层，这带来了挑战；JetBrains 的 Swift 导出功能仍在扩展和稳定中，旨在解决这一问题，覆盖大多数地道的 Swift-Kotlin 互操作所需功能的稳定版本计划于 2026 年发布。<sup>[19](https://lambdadigamma.com/assets/publications/adopting-kotlin-multiplatform-in-the-future-lab-aachen-app.pdf)</sup><sup> • </sup><sup>[12](https://kotlinlang.org/docs/native-swift-export.html)</sup><sup> • </sup><sup>[23](https://blog.jetbrains.com/kotlin/2025/08/kmp-roadmap-aug-2025/)</sup>

## References

1. [Kotlin Multiplatform, Android Developers](https://developer.android.com/kotlin/multiplatform?authuser=13)
2. [Update on the Name of Kotlin Multiplatform, The JetBrains Blog (2023)](https://blog.jetbrains.com/kotlin/2023/07/update-on-the-name-of-kotlin-multiplatform/)
3. [Android Support for Kotlin Multiplatform (KMP), Android Developers Blog (14 May 2024)](https://android-developers.googleblog.com/2024/05/android-support-for-kotlin-multiplatform-to-share-business-logic-across-mobile-web-server-desktop.html)
4. [Compose Multiplatform 1.8.0 Released: Compose Multiplatform for iOS Is Stable and Production-Ready, The JetBrains Blog (2025)](https://blog.jetbrains.com/kotlin/2025/05/compose-multiplatform-1-8-0-released-compose-multiplatform-for-ios-is-stable-and-production-ready/)
5. [Kotlin Case Studies, kotlinlang.org](https://kotlinlang.org/case-studies/)
6. [State of Kotlin 2026, kotlinlang.org](https://kotlinlang.org/state-of-kotlin-2026/)
7. [Helping Decision-Makers Say Yes to Kotlin Multiplatform (KMP), The JetBrains Blog (2026)](https://blog.jetbrains.com/kotlin/2026/04/helping-decision-makers-say-yes-to-kmp/)
8. [The basics of Kotlin Multiplatform project structure, Kotlin Multiplatform Documentation](https://kotlinlang.org/docs/multiplatform/multiplatform-discover-project.html)
9. [Building a Kotlin library for multiplatform, Kotlin Documentation](https://kotlinlang.org/docs/api-guidelines-build-for-multiplatform.html)
10. [Use platform-specific APIs, Kotlin Multiplatform Documentation](https://kotlinlang.org/docs/multiplatform/multiplatform-connect-to-apis.html)
11. [Kotlin/Native, Kotlin Documentation](https://kotlinlang.org/docs/native-overview.html)
12. [Interoperability with Swift using Swift export, Kotlin Documentation](https://kotlinlang.org/docs/native-swift-export.html)
13. [Celebrating Kotlin 2.0: Fast, Smart, and Multiplatform, The JetBrains Blog (2024)](https://blog.jetbrains.com/kotlin/2024/05/celebrating-kotlin-2-0-fast-smart-and-multiplatform/)
14. [Google @ KotlinConf 2024: A Look Inside Multiplatform Development with KMP and more, Android Developers Blog](https://android-developers.googleblog.com/2024/05/google-kotlinconf-2024-look-inside.html)
15. [Kotlin Foundation Annual Report 2024](https://kotlinfoundation.org/kf_annual_report_2024.pdf)
16. [Set up the Android Gradle library plugin for KMP, Android Developers](https://developer.android.com/kotlin/multiplatform/plugin)
17. [Compose Multiplatform 1.9.0 Released: Compose Multiplatform for Web Goes Beta, The JetBrains Blog (2025)](https://blog.jetbrains.com/kotlin/2025/09/compose-multiplatform-1-9-0-compose-for-web-beta/)
18. [Cash App Case Study, The JetBrains Blog (2021)](https://blog.jetbrains.com/kotlin/2021/03/cash-app-case-study/)
19. [Adopting Kotlin Multiplatform in the Future Lab Aachen app, LambdaDigamma](https://lambdadigamma.com/assets/publications/adopting-kotlin-multiplatform-in-the-future-lab-aachen-app.pdf)
20. [Evaluating Kotlin Multiplatform: Benefits and Trade-Offs in Cross-Platform Development, InfoQ (2025)](https://www.infoq.com/articles/kotlin-multiplatform-evaluation/)
21. [Cross-Platform vs Native Mobile Development: An Empirical Study of Software Quality Trade-offs, arXiv](https://arxiv.org/abs/2609.21544)
22. [Leveraging Kotlin Multiplatform for Modern Mobile App Development, IJTSRD](https://www.ijtsrd.com/papers/ijtsrd50077.pdf)
23. [What's Next for Kotlin Multiplatform and Compose Multiplatform – August 2025 Update, The JetBrains Blog](https://blog.jetbrains.com/kotlin/2025/08/kmp-roadmap-aug-2025/)
24. [Integration with Existing Apps · React Native](https://reactnative.dev/docs/next/integration-with-existing-apps)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Frameworks, libraries, and APIs › Mobile and platform frameworks

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/kotlin-multiplatform

English original: https://www.edgepedia.org/kotlin-multiplatform
