expect-actual

Separate shared Kotlin Multiplatform APIs from Android and iOS implementations.

61|17|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/ahmed3elshaer/everything-claude-code-mobile --skill expect-actual
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: expect-actual
Source: https://github.com/ahmed3elshaer/everything-claude-code-mobile/tree/main/skills/expect-actual
Command: npx skills add https://github.com/ahmed3elshaer/everything-claude-code-mobile --skill expect-actual

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Kotlin Multiplatform's expect/actual pattern separates shared API surface from platform-specific implementations, reducing duplication and ensuring a clean single source of truth.

Core Features & Use Cases

  • Shared interfaces: declare API contracts in commonMain and provide per-platform implementations in androidMain and iosMain.
  • Platform-specific behavior: implement platform-specific logic behind a common API without leaking platform details to shared code.
  • Use Case: build a cross-platform feature like file system access that behaves consistently on Android and iOS by supplying actual implementations for each platform.

Quick Start

Define expect declarations in commonMain to describe the API surface. Implement actual declarations in androidMain and iosMain to fulfill the platform-specific behavior. Optionally add commonTest tests to verify cross-platform consistency.

Frequently Asked Questions about expect-actual

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

FAQPage Schema
How do I share code between Android and iOS apps without duplication?

Kotlin Multiplatform's expect/actual pattern lets you declare a shared API in commonMain and provide platform-specific implementations in androidMain and iosMain. This eliminates duplication while keeping platform details isolated from shared code.

What's the difference between expect and actual declarations in Kotlin Multiplatform?

Expect declarations in commonMain define the API contract; actual declarations in platform-specific modules (androidMain, iosMain) fulfill that contract with platform-native code. This separation ensures a single source of truth for the shared interface.

Can I use expect/actual for platform-specific behavior like file system access?

Yes. Define file system access as an expect declaration in commonMain, then implement it with Android and iOS native APIs in their respective actual declarations. The shared code calls the common interface; each platform handles its own logic behind it.

Do I need to write tests when using expect/actual in Kotlin Multiplatform?

Tests in commonTest verify cross-platform consistency of your shared API. While optional, they catch implementation gaps and ensure the expect/actual contract is upheld before platform-specific code is deployed.

How do I organize expect/actual code in a Kotlin Multiplatform project?

Place expect declarations in commonMain source, then create matching actual implementations in androidMain and iosMain. File structure mirrors the common module across platforms, with the same package paths and class names linking expect to actual via compiler rules.