kotlin-multiplatform
БесплатноБез исполняемых скриптовНе проверенKotlin Multiplatform (KMP) is JetBrains' technology for sharing Kotlin code between Android, iOS, web, and desktop applications while keeping the UI native on…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Kotlin Multiplatform — Shared Business Logic for Mobile
Overview
Kotlin Multiplatform (KMP) compiles one Kotlin codebase for Android, iOS, desktop (JVM) and web. Business logic, networking and the data layer live in a shared module; each platform keeps its own UI (or shares it too with Compose Multiplatform). Platform differences are isolated behind expect/actual declarations.
Instructions
Project Structure
Create the project with the Kotlin Multiplatform wizard in IntelliJ IDEA or Android Studio (New Project > Kotlin Multiplatform). Shared code and app entry points are separate modules:
tasklane/
├── shared/ # Kotlin Multiplatform module (build.gradle.kts below)
│ └── src/
│ ├── commonMain/kotlin/ # Platform-independent code
│ ├── commonMain/sqldelight/ # .sq files (SQLDelight)
│ ├── androidMain/, iosMain/, jvmMain/ # actuals per platform (iosMain comes from the default hierarchy)
│ └── jvmTest/kotlin/ # Tests that run on any machine
├── androidApp/ # Android app (Jetpack Compose), depends on :shared
└── iosApp/ # Xcode project (SwiftUI), links the Shared framework
Gradle Setup
// shared/build.gradle.kts
plugins {
kotlin("multiplatform") version "2.4.20"
kotlin("plugin.serialization") version "2.4.20"
id("app.cash.sqldelight") version "2.4.0"
id("com.android.kotlin.multiplatform.library") version "9.4.1"
}
kotlin {
jvm()
android { // replaces androidTarget() and the top-level android {} block
namespace = "com.tasklane.shared"
compileSdk = 36
minSdk = 24
}
listOf(iosArm64(), iosSimulatorArm64()).forEach { target ->
target.binaries.framework {
baseName = "Shared" // Swift: import Shared
isStatic = true
}
}
sourceSets {
commonMain.dependencies {
implementation("io.ktor:ktor-client-core:3.6.0")
implementation("io.ktor:ktor-client-content-negotiation:3.6.0")
implementation("io.ktor:ktor-serialization-kotlinx-json:3.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0")
implementation("app.cash.sqldelight:coroutines-extensions:2.4.0")
implementation("org.jetbrains.androidx.lifecycle:lifecycle-viewmodel:2.11.0")
}
commonTest.dependencies {
implementation(kotlin("test"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.11.0")
implementation("io.ktor:ktor-client-mock:3.6.0")
}
// One HTTP engine and one SQLite driver per platform
androidMain.dependencies { implementation("io.ktor:ktor-client-okhttp:3.6.0"); implementation("app.cash.sqldelight:android-driver:2.4.0") }
jvmMain.dependencies { implementation("io.ktor:ktor-client-okhttp:3.6.0"); implementation("app.cash.sqldelight:sqlite-driver:2.4.0") }
iosMain.dependencies { implementation("io.ktor:ktor-client-darwin:3.6.0"); implementation("app.cash.sqldelight:native-driver:2.4.0") }
}
}
sqldelight { databases { create("TaskDatabase") { packageName.set("com.tasklane.db") } } }
Useful tasks: ./gradlew :shared:jvmTest (shared tests on the JVM), :shared:iosSimulatorArm64Test (macOS only), :shared:allTests. Xcode builds the framework through a run-script phase that calls ./gradlew :shared:embedAndSignAppleFrameworkForXcode.
Local Database with SQLDelight
-- shared/src/commonMain/sqldelight/com/tasklane/db/Task.sq
-- SQLDelight generates TaskDatabase, TaskEntity and typed query functions from this file.
CREATE TABLE TaskEntity (
id TEXT NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'TODO',
pending_sync INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL
);
selectAll:
SELECT * FROM TaskEntity ORDER BY created_at DESC;
upsert:
INSERT OR REPLACE INTO TaskEntity(id, title, status, created_at) VALUES (?, ?, ?, ?);
markPendingSync:
UPDATE TaskEntity SET pending_sync = 1 WHERE id = ?;
Platform-Specific Code with expect/actual
// shared/src/commonMain/kotlin/com/tasklane/shared/Platform.kt
// 'expect' declares what each platform must implement.
expect fun platformName(): String
expect class DriverFactory {
fun createDriver(): SqlDriver
}
// shared/src/androidMain/kotlin/com/tasklane/shared/Platform.android.kt
actual fun platformName(): String = "Android ${android.os.Build.VERSION.SDK_INT}"
actual class DriverFactory(private val context: Context) {
actual fun createDriver(): SqlDriver = AndroidSqliteDriver(TaskDatabase.Schema, context, "tasks.db")
}
// shared/src/iosMain/kotlin/com/tasklane/shared/Platform.ios.kt
actual fun platformName(): String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
actual class DriverFactory {
Установить kotlin-multiplatform в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл kotlin-multiplatform?
Kotlin Multiplatform (KMP) is JetBrains' technology for sharing Kotlin code between Android, iOS, web, and desktop applications while keeping the UI native on each platform. Use when a user asks to set up a KMP shared module, share business logic, networking or a data layer between Android and iOS, write expect/actual declarations, use Ktor or SQLDelight in commonMain, write a shared ViewModel, test shared code, or migrate a KMP project to Android Gradle Plugin 9.
Как установить скилл kotlin-multiplatform?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл kotlin-multiplatform запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic