用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/G1Joshi/Agent-Skills --skill kotlin-multiplatform命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | kotlin-multiplatform |
| description | Kotlin Multiplatform for shared code. Use for cross-platform. |
Kotlin Multiplatform (KMP) allows you to share code between Android, iOS, Web, and Desktop. It emphasizes sharing logic (Business, Data, Networking) while allowing for native or shared (Compose Multiplatform) UIs.
// commonMain/kotlin/Platform.kt
interface Platform {
val name: String
}
expect fun getPlatform(): Platform
// androidMain/kotlin/Platform.kt
actual fun getPlatform(): Platform = object : Platform {
override val name = "Android ${android.os.Build.VERSION.SDK_INT}"
}
// iosMain/kotlin/Platform.kt
import platform.UIKit.UIDevice
actual fun getPlatform(): Platform = object : Platform {
override val name = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
}
// commonMain/kotlin/Greeting.kt
class Greeting {
fun greet(): String = "Hello, ${getPlatform().name}!"
}
Mechanism to define an interface in common code (expect) and provide platform-specific implementations (actual) in platform modules.
A Gradle module usually named shared or composeApp. This compiles to an .aar for Android and a .framework (or XCFramework) for iOS.
Google's declarative UI framework (Jetpack Compose) ported to iOS, Web, and Desktop by JetBrains. Allows sharing UI code 100%.
Use Ktor for multiplatform networking and kotlinx.serialization for JSON parsing. Both are pure Kotlin and work on all targets.
Use SQLDelight or Room (KMP support active) for type-safe database access shared across platforms.
Koin is a popular pure Kotlin dependency injection framework that works seamlessly in KMP to manage singletons and factories.
Do:
commonTest.Don't:
commonMain (only pure Kotlin).expect/actual usage if a library (like KMP-NativeCoroutines) can solve the bridging better.| Error | Cause | Solution |
|---|---|---|
Unresolved reference in commonMain | Using platform-specific API (java.util, android.*). | Use KMP-compatible libraries (kotlinx-datetime). |
C-interop build errors | iOS build configuration or missing headers. | Check cocoapods or framework config in build.gradle.kts. |
Memory Leaks on iOS | Circular references or freezing (mostly solved in new memory model). | Ensure newer Kotlin version (1.9+) is used. |