| name | kmp-cmp-app-builder |
| description | Use when building, developing, or shipping Kotlin Multiplatform (KMP) and Compose Multiplatform (CMP) applications targeting Android, iOS, and Desktop. Covers the full project lifecycle: initial setup with multi-module Clean Architecture, active development (adding features, networking, database, authentication, offline-first sync, testing), and production release (ProGuard, signing, CI/CD). Use this skill when the user asks to create a KMP or CMP app, add feature modules, implement networking or database layers, set up authentication, write tests, prepare release builds, or follow multiplatform code conventions โ even if they don't explicitly mention "multiplatform" or "KMP", such as asking to share code between Android and iOS or build a cross-platform app.
|
| compatibility | Requires Android Studio Ladybug or later (or IntelliJ IDEA with KMP plugin), JDK 17+, Xcode 15+ for iOS targets, Kotlin 2.1+, Compose Multiplatform 1.7+, and AGP 9.1+.
|
| metadata | {"author":"kmp-expert","version":"4.1"} |
KMP/CMP Application Builder
Covers the complete lifecycle of a KMP/CMP application: setup โ development โ production.
When to use
Phase 1 โ Setup: Creating a new project, configuring Gradle, convention plugins, core modules.
Phase 2 โ Development: Adding features, implementing networking/database/auth, offline-first, testing.
Phase 3 โ Production: ProGuard/R8, signing, CI/CD, performance, release builds.
Architecture
Use multi-module Clean Architecture:
root/
โโโ build-logic/convention/ # Gradle convention plugins
โโโ androidApp/ # Pure Android entry point (Activity, Manifest)
โโโ composeApp/ # Composition root & shared UI (Android, iOS, Desktop)
โโโ core/
โ โโโ domain/ # Pure Kotlin: models, Result, interfaces
โ โโโ data/ # Ktor, DataStore, session, HttpClientFactory
โ โโโ presentation/ # UiText, shared composables
โ โโโ designsystem/ # Theme, colors, typography, components
โโโ feature/<name>/
โ โโโ domain/ # Feature models + repository interfaces
โ โโโ data/ # Repository implementation
โ โโโ database/ # Room entities + DAOs (optional)
โ โโโ presentation/ # ViewModel (MVI) + screens
โโโ gradle/libs.versions.toml
โโโ settings.gradle.kts
Dependency rules (CRITICAL)
androidApp โ composeApp
composeApp โ core/* + feature/*/
feature/*/presentation โ feature/*/domain + core/presentation + core/designsystem
feature/*/data โ feature/*/domain + core/domain + core/data
feature/*/database โ feature/*/domain
core/data โ core/domain
core/presentation โ core/domain + core/designsystem
- domain = pure Kotlin, ZERO framework imports
- data implements domain interfaces
- presentation depends on domain only, never on data
- Feature modules NEVER depend on other feature modules
- composeApp wires all DI and navigation
Phase 1: Setup
-
Initialize project โ settings.gradle.kts, libs.versions.toml, root build.gradle.kts, build-logic/.
See PROJECT_SETUP.md.
-
Create convention plugins โ KmpLibrary, CmpLibrary, CmpFeature, CmpApplication, Room, BuildKonfig, Kover.
See CONVENTION_PLUGINS.md.
-
Set up core modules โ domain (Result, DataError), data (HttpClientFactory, auth), designsystem (AppTheme), presentation (UiText).
See CORE_MODULES.md.
-
Wire composeApp โ Koin DI graph, NavHost, platform entry points.
See APP_WIRING.md.
Phase 2: Development
Adding a feature module
See FEATURE_MODULES.md for complete patterns.
Security & authentication
See SECURITY.md.
Offline-first features
See OFFLINE_FIRST.md.
Testing & coverage
See TESTING.md.
Code conventions
Follow naming rules and patterns throughout development.
See CODE_CONVENTIONS.md.
Debugging quick reference
| Problem | Solution |
|---|
| HTTP issues | Ktor Logging (all platforms) |
| DI resolution fails | Core modules must load before features in Koin |
| Database migration error | Check Room schema dir, verify migration steps |
| Flow not emitting | Check SharingStarted.WhileSubscribed(5_000) |
| Platform crash | Separate expect/actual, use Kermit for logging |
Phase 3: Production
Configure ProGuard, signing, CI/CD, optimize performance, and run the pre-release checklist.
See PRODUCTION.md.
Validation before release
./gradlew build โ compiles without errors
./gradlew allTests โ all tests pass
./gradlew koverVerify โ coverage โฅ 60%
./gradlew :androidApp:assembleRelease โ release APK builds
./gradlew :androidApp:bundleRelease โ release AAB for Play Store
- Test release build on physical device
Gotchas
- Token refresh must skip auth endpoints โ otherwise infinite loop when refresh token expires.
- Always call
BearerAuthProvider.clearToken() on logout โ cached tokens persist.
- API keys go in
local.properties only โ never commit secrets.
- Offline-first UI must observe Room
Flow, not network responses.
- Never catch
CancellationException โ always re-throw.
TYPESAFE_PROJECT_ACCESSORS must be enabled in settings.gradle.kts.
- DataStore file path needs
expect/actual โ each platform stores differently.
- Desktop target needs
kotlinx-coroutines-swing for coroutine dispatching.
- Navigation Compose routes must be
@Serializable data objects/classes.
- ProGuard must keep
@Serializable classes โ JSON parsing breaks in release.
- Always use
bundleRelease (AAB) for Play Store, not assembleRelease (APK).
- Kover
koverVerify will fail CI if coverage drops below minimum bound.
- Use
Dispatchers.setMain(testDispatcher) in @BeforeTest and resetMain() in @AfterTest.
- Never use
println() or Log.d() โ use Kermit (multiplatform) or Timber (Android-only).
- AGP 9 + KMP Library Plugin: The project uses
com.android.kotlin.multiplatform.library. This requires AGP 9 and changes Android target config (no android { ... } blocks needed in pure KMP modules).
- Kover 0.9.x vs AGP 9: Kover crashes on KMP library modules due to missing Android variants. The
KoverConventionPlugin injects a spoofed empty android extension to bypass this.
- ViewModel Test Deadlocks: Tests with Turbine can hang if IO dispatchers are active. Cancel unconsumed events before the test ends or manually cancel the scope.
- Test Discovery Failure: Modules with Kover applied but zero tests will fail the build with "No tests discovered" errors during Kover tasks. Always add a dummy test if needed.
Technology stack
| Technology | Purpose | Version |
|---|
| AGP | Android build tools | 9.1+ |
| Kotlin | Language | 2.1+ |
| Compose Multiplatform | UI framework | 1.7+ |
| Koin | DI | 4.0+ |
| Ktor | HTTP + WebSockets | 3.0+ |
| Room | Database (offline-first) | 2.7+ |
| Navigation Compose | Navigation | Aligned with CMP |
| DataStore | Session storage | 1.1+ |
| Kover | Test coverage | 0.9+ |
| Turbine | Flow testing | 1.2+ |
| BuildKonfig | Build constants | 0.15+ |
| Kermit | Multiplatform logging | 2.0+ |
| Coil | Image loading | 3.0+ |
| MOKO Permissions | Permissions | 0.18+ |