kmp-fundamentals
Skill0 starsChanged 35 days agoMITView on GitHub
Kotlin Multiplatform fundamentals: source-set discipline, expect/actual placement and balance, and multiplatform dependency choices. Use when writing or reviewing code in commonMain/platform source sets, adding expect declarations, or migrating shared logic to KMP. Core rules have machine checks in checks/.
In this repository11 other files it gives its agents.
- android-testingSkill
- compose-architectureSkill
- compose-migrationSkill
- compose-multiplatformSkill
- compose-performanceSkill
- compose-testingSkill
- dependency-injectionSkill
- gradle-build-logicSkill
- material3-themingSkill
- offline-firstSkill
- release-engineeringSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 2 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
After ANY expect/actual or source-set edit, run the Verification step (bottom of this file).
- Very specific: line 21
MUST keep common source sets (commonMain, commonTest) free of platform SDK imports: android.*, java.* / javax.*, com.android.*, …
- Very specific: line 55
MUST declare expect in the common source set and actual in each platform-specific source set, in the same package — never the reverse.
- Very specific: line 78
Every expect declaration MUST have an actual in every declared platform source set.
- Very specific: line 83
Prefer not needing expect/actual at all: "rely on standard language constructs wherever possible" — a common interface with platform …
- Very specific: line 108
Add dependencies per source set: commonMain.dependencies { } for shared code, androidMain.dependencies { } for Android-only.
- Very specific: line 118
No deterministic check covers dependency wiring.
- Very specific: line 123
Run after every KMP-related edit (from the module's src root, i.e.
- Distinctive: line 132
All three must pass (exit 0) before declaring the task done.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
KMP Fundamentals
Operational rules for a coding agent. RIGHT/WRONG pairs are canonical. After ANY expect/actual or source-set edit, run the Verification step (bottom of this file). The checks give pre-compile feedback in seconds — the compiler stays the ground truth.
1. Source-set discipline — no platform APIs in common
MUST keep common source sets (commonMain, commonTest) free of platform
SDK imports: android.*, java.* / javax.*, com.android.*,
com.google.android.*, androidx.activity.*, and Kotlin/Native
platform.*. Common code compiles to every target, where those SDKs do
not exist ("you can't use the java.io.File dependency from the common
code").
WRONG:
// commonMain/.../Greeting.kt
import java.io.File
fun greeting() {
File("greeting.txt").writeText("Hello, Multiplatform!")
}RIGHT:
// commonMain/.../Greeting.kt
import kotlinx.io.files.Path
fun greeting() {
// use a multiplatform library (kotlinx-io, Ktor, kotlinx-datetime, ...)
}androidx.compose.* / material3 and other Compose Multiplatform artifacts
are intentionally NOT flagged: they ship a common API. Shared platform-
family code (e.g. Apple APIs) belongs in intermediate source sets
(appleMain), not in commonMain.
2. expect/actual placement
MUST declare expect in the common source set and actual in each
platform-specific source set, in the same package — never the reverse.
WRONG:
// androidMain/.../Platform.android.kt
expect fun androidApiLevel(): Int // expect belongs in commonMain
// commonMain/.../Platform.kt
actual fun logTag(): String = "shared" // actual belongs in a platform setRIGHT:
// commonMain/.../Platform.kt
expect fun androidApiLevel(): Int
// androidMain/.../Platform.android.kt
actual fun androidApiLevel(): Int = Build.VERSION.SDK_INT3. expect/actual balance — and prefer interfaces
Every expect declaration MUST have an actual in every declared
platform source set; an actual without a matching expect does not
compile. The check below verifies the name balance across the whole
module before you build.
Prefer not needing expect/actual at all: "rely on standard language
constructs wherever possible" — a common interface with platform
implementations (wired by DI or a small expect/actual factory) beats
expect class. Expected/actual classes are Beta and recommended only for
inheriting platform classes.
WRONG:
// commonMain
expect class Logger() {
fun log(message: String)
}RIGHT:
// commonMain
interface Logger {
fun log(message: String)
}
expect fun buildLogger(): Logger // actualized per platform or via DI4. Dependencies & libraries (review-verified)
- Add dependencies per source set:
commonMain.dependencies { }for shared code,androidMain.dependencies { }for Android-only. - In common code prefer multiplatform libraries —
kotlinx-coroutines,kotlinx-datetime,kotlinx-io,Ktor client,kotlinx.serialization— over platform APIs. - Platform-only libraries (Guava, Spring, Room desktop variants) go to the corresponding platform source set.
- Tests mirror sources:
commonTestcompiles to all targets; usekotlin.testthere, platform frameworks only in platform test sets.
No deterministic check covers dependency wiring; verify against references/kmp.md.
Verification
Run after every KMP-related edit (from the module's src root, i.e. the parent of commonMain/androidMain/...):
bash <skill-dir>/checks/check_no_platform_imports_in_common.sh <src-root>
bash <skill-dir>/checks/check_expect_actual_placement.sh <src-root>
bash <skill-dir>/checks/check_expect_actual_balance.sh <src-root>All three must pass (exit 0) before declaring the task done. Checks are deterministic file-level heuristics; per-target actual coverage and signature matching are the compiler's job — the balance check catches the forgotten platform file before you pay for a build.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

