kotlin-multiplatform-expect-actual

Designs expect/actual and interface boundaries for Kotlin Multiplatform platform services.

Updated Jul 1, 2026
One-click install
npx skills add https://github.com/w0lzard/Wolzard-s-Marketplace --skill kotlin-multiplatform-expect-actual-w0lzard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-multiplatform-expect-actual
Source: https://github.com/w0lzard/Wolzard-s-Marketplace/tree/main/plugins/personal-skills/skills/kotlin-multiplatform-expect-actual
Command: npx skills add https://github.com/w0lzard/Wolzard-s-Marketplace --skill kotlin-multiplatform-expect-actual-w0lzard

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Kotlin Multiplatform projects often leak Android or iOS types into commonMain, making shared code untestable and hard to extend to new platforms. This Skill guides the design of clean expect/actual declarations and interface boundaries so common code stays semantic and platform details stay isolated. ## Core Features & Use Cases - Boundary Selection: Decide between expect/actual declarations, common interfaces with platform bindings, or separate platform screens based on lifecycle, DI, and testing needs. - Semantic Common APIs: Keep commonMain free of platform types like Context, Activity, UIViewController, or Android resource IDs. - Compose Multiplatform Guidance: Push platform-specific composables to leaf nodes, pass Modifier through expected composables, and handle effects with LaunchedEffect and DisposableEffect. - Use Case: When adding a share sheet to a KMP app, define a semantic ShareSheet interface in commonMain, bind an Activity-owned Android implementation, and use a fake in common tests. ## Quick Start Ask the AI to design an expect/actual boundary for a platform capability such as clipboard, haptics, or file access in your Kotlin Multiplatform project.

Frequently Asked Questions about kotlin-multiplatform-expect-actual

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use expect/actual in Kotlin Multiplatform?

Declare a semantic expect function, value, or class in commonMain and provide platform-specific actual implementations in androidMain, iosMain, or desktopMain. Keep the common API free of platform types so callers never know which platform APIs are used.

When should I use an interface instead of expect/actual in KMP?

Use an interface when the implementation needs injected dependencies, lifecycle ownership, runtime selection, or test fakes. Use expect/actual for simple compile-time platform specialization like leaf functions or typealiases.

Can commonMain code reference Android Context or Activity?

No, commonMain should avoid platform types like Context, Activity, Uri, or UIViewController in API signatures. Hide those requirements inside the platform actual or behind an interface bound by platform code.

How do I handle platform-specific UI in Compose Multiplatform?

Push platform-specific composables to leaf nodes and pass Modifier through every expected composable that emits UI. Use interop containers like AndroidView or UIKitView inside the actual, and manage lifecycle with LaunchedEffect and DisposableEffect.

Why is my KMP actual implementation getting too complex?

Actuals should only translate the semantic API into platform calls. If business rules accumulate in an actual, move those rules back to common code and leave only platform translation in the actual.