android-kmp-shared
Use when building Kotlin Multiplatform (KMP) shared modules, integrating with iOS, or sharing business logic across platforms.
Works with
---
name: android-kmp-shared
description: Use when building Kotlin Multiplatform (KMP) shared modules, integrating with iOS, or sharing business logic across platforms.
license: MIT
---
# Android Kotlin Multiplatform (KMP) ππ€
Professional patterns for sharing code between Android and iOS using the next-generation Kotlin Multiplatform technology.
## β‘ When to Use
- **Shared Business Logic**: Centralizing ViewModels, Use Cases, and Domain Models.
- **Data Layer Sharing**: Using Ktor (Network) and SQLDelight (Database) across platforms.
- **Modularization**: Creating a cross-platform library module.
- **Migration**: Moving from 100% native to shared logic.
- **Validation**: Building one logic for both apps (e.g., Auth, Calculations).
## ποΈ The Multiplatform Architecture
- **`commonMain`**: The heart of the app. Pure Kotlin code shared by all platforms.
- **`androidMain`**: Platform-specific implementation for Android.
- **`iosMain`**: Platform-specific implementation for iOS (via Kotlin/Native).
## π οΈ Essential Shared Tools
### 1. Ktor (Networking)
- **Benefit**: Async, multiplatform HTTP client.
- Use `ContentNegotiation` and `Serialization` for shared DTOs.
### 2. SQLDelight (Local Persistence)
- **Benefit**: Type-safe SQL queries that generate Kotlin code.
- Shared schema, platform-specific drivers (SQLite for Android, Native for iOS).
### 3. Koin (Dependency Injection)
- **Benefit**: Simple and lightweight DI that works across `commonMain`.
### 4. kotlinx-datetime
- Use for consistent date/time logic without platform-specific issues (java.time vs NSDate).
## π The `expect` / `actual` Pattern
- Use for platform-specific APIs when no shared library exists.
- **Rule**: Avoid `expect`/`actual` if a shared library is available.
- **Bad**: `expect fun getPlatformName(): String`
- **Good**: Use **interfaces** and **DI** to provide platform-specific implementations.
## π Shared Logic Workflow
- [ ] **ViewModel Sharing**: Use `multiplatform-viewmodel` library for consistent lifecycle mapping.
- [ ] **State Management**: Use `StateFlow` in `commonMain` to expose UI state.
- [ ] **iOS Interoperability**: Be aware of Swift/Kotlin memory management and `@ObjCName` for clean iOS APIs.
## π¦ Gradle Configuration
```kotlin
kotlin {
androidTarget()
iosX64()
iosArm64()
iosSimulatorArm64()
sourceSets {
commonMain.dependencies {
implementation("io.ktor:ktor-client-core:2.3.0")
}
}
}
```
## π§ͺ Testing with KMP
- Tests in `commonTest` run on both Android and iOS targets.
- Use `kotlin.test` for standard assertions (`assertTrue`, `assertEquals`).
- Mocking: Use libraries like **Mockative** or **KMock** for multiplatform mocking.
## π Related Resources
- [KMP Official Guide](https://kotlinlang.org/docs/multiplatform.html)
- [KMP Samples (By JetBrains)](https://github.com/Kotlin/kmp-samples)
- [Clean Architecture Skill](../android-clean-architecture/SKILL.md)More Mobile skills
animation-vocabulary
emilkowalski/skills
Reverse-lookup glossary that turns a vague description of a web animation or motion effect into its exact term ("the bouncy thing when a popover opens" β Pop in; "the iOS rubber-band scroll" β Rubber-banding). Use when the user asks "what's it called whenβ¦", or describes a motion effect without knowing its name and wants the right word to prompt an AI or designer with. For naming an effect, not designing or building one.
xcode-project-setup
firebase/agent-skills
Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).
cross-border-ecommerce
nexscope-ai/ecommerce-skills
Cross-border e-commerce expansion advisor. Scores target markets on 8 weighted dimensions (market size, ecommerce penetration, competition, regulatory complexity, logistics infrastructure, payment ecosystem, cultural distance, IP protection), compares 5 fulfillment models with cost and transit data, provides country-by-country tax/duty compliance guides (EU VAT/IOSS, UK VAT, US sales tax, CA GST, AU GST, JP consumption tax), maps local payment preferences by market, and builds a phased expansion roadmap. No API key required.

