Claude Cursor Skill

android-to-kmp-migration

Use when an existing Android app (Kotlin, Jetpack, Views or Compose) should share code with iOS through Kotlin Multiplatform - "migrate to KMP", "add iOS to our Android app", "make this module multiplatform", "create a shared module", splitting an androidApp entry module from sha

LLM Mart · 0 points · 0 views 4 listing impressions 0 install-command copies
Download kushpawan-kmp-mobile-skills-skills_android-to-kmp-migration-c04c11f.zip · 12 KB

Install

skills CLI npx skills add https://github.com/Kushpawan/kmp-mobile-skills/tree/main/skills/android-to-kmp-migration
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install kushpawan-kmp-mobile-skills@llmmart
Git git clone https://github.com/Kushpawan/kmp-mobile-skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole kushpawan/kmp-mobile-skills collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

Android to Kotlin Multiplatform migration

Migrate in thin, shippable slices: create a shared module, prove one vertical slice runs on iOS early, then move code inward-out — domain, data, presentation, and only then (optionally) UI. The Android app must be releasable after every merged step. A migration that lives on a long branch, or that leaves iOS until the end, is where these projects stall.

The target is the AGP 9 layout: the Android app stays a plain Android entry module (:androidApp, or the existing :app), and shared code lives in a separate KMP module on com.android.kotlin.multiplatform.library with kotlin { android { } }. Never apply the Kotlin Multiplatform plugin to the app module.

When to use

  • An Android app needs an iOS version and the team wants to share business logic.
  • A module or package should become multiplatform without rewriting the app.
  • Deciding which Android libraries to replace, keep, or hide behind interfaces.
  • Estimating and sequencing the migration for a team.

When not to use

  • The project is already KMP and only needs AGP 9 (androidTarget() to the Android-KMP plugin, app module split): JetBrains' kotlin-tooling-agp9-migration.
  • Upgrading the pure-Android app module to AGP 9 (built-in Kotlin, new DSL, kapt): Google's agp-9-upgrade. It says it is not for KMP projects, so use it on the Android app before :shared exists, or on the app module only.
  • Converting Java sources to Kotlin first: JetBrains' kotlin-tooling-java-to-kotlin, then return.
  • Adding one new feature module to a project that is already KMP: use kmp-feature-module.
  • One expect/actual pair: use kmp-expect-actual.

Step 0 — Read the project first

cat settings.gradle.kts; find . -name build.gradle.kts -not -path '*/build/*' | sort
sed -n '1,80p' gradle/libs.versions.toml               # Kotlin, AGP, Compose, library versions
cat gradle/wrapper/gradle-wrapper.properties gradle.properties
grep -rnE 'kotlin\("kapt"\)|kotlin-kapt|org.jetbrains.kotlin.kapt' --include='*.kts' .   # kapt users
grep -rnE 'org.jetbrains.kotlin.android|kotlin\("android"\)|kotlinAndroid' --include='*.kts' .  # pre-AGP-9 Kotlin plugin
grep -rnE 'enableLegacyVariantApi|builtInKotlin|newDsl' gradle.properties   # AGP 9 opt-outs in use
grep -rhoE '^import (android|androidx|dagger|javax\.inject|io\.reactivex|com\.google\.gson|com\.squareup\.(retrofit2|moshi)|com\.bumptech|java\.time|timber)[.a-z]*' \
  --include='*.kt' app/src/main | sort | uniq -c | sort -rn | head -40   # what the code leans on
grep -rlE 'BuildConfig\.' --include='*.kt' . | head                     # config that must be injected later
find . -path '*/src/main/java' -o -path '*/src/main/kotlin' | head     # source roots per module
ls app/src/main/res/layout 2>/dev/null | wc -l                         # View-based UI size

Record: modules and their dependencies, Kotlin/AGP/Gradle versions, DI framework, async style (coroutines, RxJava, LiveData), networking, persistence, image loading, logging, UI toolkit (Views, Compose, mixed), test style, whether kapt and BuildConfig are in use, and which gradle.properties opt-outs exist. Ask the team two decisions before planning:

  1. iOS UI: Compose Multiplatform (share UI too) or native SwiftUI over shared logic?
  2. DI: move the shared graph to a KMP DI library, or keep Hilt in the Android app and build the iOS graph separately?

Target layout

settings.gradle.kts    include(":androidApp", ":shared")   # keep ":app" if that is the existing name
androidApp/            com.android.application (+ Compose compiler plugin if Compose)
  src/main/            Application, Activities, manifest, signing, flavours, BuildConfig
shared/                org.jetbrains.kotlin.multiplatform + com.android.kotlin.multiplatform.library
  src/commonMain/  src/androidMain/  src/iosMain/  src/commonTest/  src/androidHostTest/
iosApp/                Xcode project; SwiftUI App or UIKit with UIScene lifecycle

What changes from a pre-AGP-9 KMP template:

Old pattern Status Use instead
KMP plugin + com.android.application in one module Not supported with AGP 9 Separate Android entry module depending on :shared
androidTarget() + com.android.library Deprecated in Kotlin 2.5 for every AGP version; on AGP 9 only behind legacy opt-outs that AGP 10 removes com.android.kotlin.multiplatform.library + kotlin { android { } }
kotlin { androidLibrary { } } Deprecated since AGP 9.1.0-alpha09 kotlin { android { } } (AGP 8.12+)
org.jetbrains.kotlin.android in the app Deprecated in Kotlin 2.5; AGP 9 compiles Kotlin itself Remove the plugin (built-in Kotlin)
debugImplementation(ui-tooling) in the shared module The plugin has no build types "androidRuntimeClasspath"(...) (AGP 9.0.0-beta01+)
BuildConfig read from shared code Not generated by the Android-KMP plugin Config interface injected from the app; or BuildKonfig
src/main, src/test, src/androidTest in the shared module Not read by the new plugin src/androidMain, src/androidHostTest, src/androidDeviceTest
kapt Incompatible with AGP 9 built-in Kotlin KSP, or com.android.legacy-kapt as a stopgap

Workflow

Write the plan with mobile-feature-plan (one phase per step below), then execute it with mobile-feature-implement. Each step ends with the Android release build and tests green.

1. Assess and classify

For each package or module, put it in one bucket:

Bucket Signal Action
Pure Kotlin no android.*, java.* (other than trivial), or Android-only library imports Moves to commonMain as is
Android API at the edges Context, SharedPreferences, ConnectivityManager, file paths, Build, BuildConfig Interface or expect/actual; Android impl moves to androidMain or the app
Android-only library Retrofit, Gson, Hilt annotations, RxJava, Glide, Timber, java.time Swap per references/library-swap.md, or hide behind an interface
UI Activities, Fragments, XML, Compose screens Last; optional

Summary of the library swaps (details, caveats and per-library notes in the reference):

Android KMP
Retrofit + OkHttp Ktor client (OkHttp engine on Android, Darwin on iOS)
Gson / Moshi kotlinx.serialization
Room 2 Room 3 (androidx.room3) for new KMP code, or Room 2.8 KMP artifacts — kmp-room-database
Hilt / Dagger Koin 4 (Compiler Plugin optional — kmp-koin-di), kotlin-inject or Metro; or keep Hilt in the Android app only
java.time kotlinx-datetime + kotlin.time.Instant / kotlin.time.Clock
RxJava coroutines + Flow (bridge with kotlinx-coroutines-rx3)
LiveData StateFlow
androidx ViewModel androidx lifecycle-viewmodel (KMP artifacts)
Glide Coil 3
SharedPreferences DataStore Preferences (KMP)
Timber Kermit or Napier
BuildConfig fields An AppConfig interface the app implements and binds in DI

Done when: every package has a bucket and every Android-only dependency has a decision.

2. Prepare the build

  • Align versions with the Kotlin Multiplatform compatibility guide. Kotlin 2.5 needs AGP 8.8.2+, Gradle 8.14–9.8.1 and a JDK 17 runtime for the compiler; AGP 9 needs Gradle 9.1+.
  • Move the Android app to AGP 9 first, while it is still Android-only: built-in Kotlin (drop org.jetbrains.kotlin.android), the new DSL, kapt to KSP, and removal of gradle.properties opt-outs. Google's agp-9-upgrade skill covers exactly this for a pure-Android build.
  • If the app module itself must stay on AGP 8 for now, still create :shared on the Android-KMP plugin (it needs AGP 8.10+; use android { } from 8.12, androidLibrary { } below that). Do not start new shared code on androidTarget().
  • Move hardcoded dependency versions into gradle/libs.versions.toml (kmp-gradle-version-catalog).

Done when: the Android app builds and releases on the target Kotlin/AGP versions, unchanged.

3. Create :shared and ship it empty

# gradle/libs.versions.toml — reuse the project's existing version keys
[plugins]
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
android-kotlin-multiplatform-library = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" }
# Usually present already for the app; add only if missing.
android-application = { id = "com.android.application", version.ref = "agp" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
// shared/build.gradle.kts
plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.android.kotlin.multiplatform.library)
}

kotlin {
    android {                       // not androidTarget(); not androidLibrary { } (deprecated)
        namespace = "com.example.app.shared"   // must differ from the app's namespace
        compileSdk = libs.versions.android.compileSdk.get().toInt()
        minSdk = libs.versions.android.minSdk.get().toInt()
        withHostTest { }            // off by default; enables src/androidHostTest
        // androidResources { enable = true }  — add when shared code uses res/ or Compose resources
    }
    listOf(iosArm64(), iosSimulatorArm64()).forEach { target ->   // add iosX64() only if Intel simulators matter
        target.binaries.framework {
            baseName = "Shared"
            isStatic = true
        }
    }
    sourceSets {
        commonMain.dependencies {
            implementation(libs.kotlinx.coroutines.core)
        }
        commonTest.dependencies {
            implementation(libs.kotlin.test)
        }
    }
}

The app module stays an Android application and only gains a dependency:

// androidApp/build.gradle.kts (or the existing app/build.gradle.kts)
plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.compose.compiler)   // only if the app uses Compose
    // No org.jetbrains.kotlin.android and no Kotlin Multiplatform plugin: AGP 9 compiles Kotlin.
}

dependencies {
    implementation(project(":shared"))
}

Add include(":shared") to settings.gradle.kts and the new plugins with apply false in the root build file. Merge this alone. Other opt-ins of the Android-KMP plugin (withDeviceTest {}, withJava(), consumer keep rules) are listed in kmp-feature-module.

Done when: :androidApp (or :app) builds a release with :shared on its classpath, and ./gradlew :shared:iosSimulatorArm64Test runs on macOS.

4. Bring up an iOS vertical slice early

Before moving much code, prove the iOS path end to end:

  1. Create the iOS app (the KMP wizard's iosApp, or an Xcode project) and integrate the framework — direct integration runs ./gradlew :shared:embedAndSignAppleFrameworkForXcode from an Xcode build phase; SPM integration is the alternative (kmp-xcframework-distribution).
  2. Use scene lifecycle from day one. Apple (WWDC26 session 278): "UIScene lifecycle is now required when building with the latest SDKs." A SwiftUI @main App already uses scenes. A UIKit host needs a UIWindowSceneDelegate and a scene manifest, not a window built in AppDelegate.
  3. Call one shared function from Swift, then one real use case that does I/O (for example "load the current user's profile" through the shared repository).
  4. Check Swift ergonomics on that slice: suspend functions, Flow, sealed classes and default arguments are where Swift friction appears (kmp-swiftui-interop, which also covers Swift export).

Done when: the iOS app shows real data from shared code on a simulator, built from a clean checkout.

5. Move the domain

Move models, validators, use cases and pure business rules to commonMain. Keep the same package names so Android imports do not change. Replace java.time with kotlinx-datetime plus kotlin.time.Instant / Clock (kotlinx-datetime 0.7+ deprecates its own Instant), java.util.UUID with kotlin.uuid.Uuid (check whether your Kotlin version still needs an opt-in), and String.format with string templates. Move their unit tests to commonTest so they run on both platforms.

Done when: domain tests pass in testAndroidHostTest and iosSimulatorArm64Test; Android release builds.

6. Move the data layer

One data source at a time, behind the repository interface the app already uses:

  • Networking: Ktor + kotlinx.serialization in commonMain; per-platform engines. Keep the Retrofit implementation bound in Android DI until the Ktor one passes the same tests, then switch the binding and delete the old one.
  • Persistence: Room 3 (androidx.room3) for a new shared database, or Room 2.8 KMP when the team wants to keep the androidx.room package for now; SQLDelight if the team prefers. Key-value with DataStore. Setup, KSP per target and the Room 2 to Room 3 move are in kmp-room-database.
  • DI for the shared graph: kmp-koin-di (Koin 4, optionally with the Koin Compiler Plugin for build-time graph checks), or keep Hilt in the app.
  • Config: replace BuildConfig reads with an interface in commonMain that the app implements from its own BuildConfig and binds in DI.
  • Platform pieces (connectivity, file paths, secure storage) behind interfaces with androidMain/iosMain implementations (kmp-expect-actual, kmp-secure-storage).

Done when: each repository has one implementation in commonMain, tested with fakes, used by Android.

7. Move presentation (ViewModels)

Use androidx lifecycle-viewmodel in commonMain. Replace LiveData with StateFlow (Android screens can collect it, or bridge with asLiveData() temporarily). Inject dispatchers. Android Fragments/Compose screens keep working against the same ViewModels; the iOS app consumes them through a Swift wrapper.

Done when: ViewModel tests run on both platforms and both apps use the shared ViewModels for the migrated features.

8. Optionally move UI to Compose Multiplatform

Only if the team chose shared UI. View-based screens go to Jetpack Compose first, in the Android app, with Google's migrate-xml-views-to-jetpack-compose skill. Then the Compose code moves to commonMain: replace R.string/R.drawable with Compose Multiplatform resources (the shared module needs androidResources { enable = true }), Android-only Compose APIs with multiplatform equivalents, and Coil 2/Glide with Coil 3. Preview tooling goes on "androidRuntimeClasspath"(...). MainActivity stays in the app module. Migrate screen by screen behind the existing navigation.

9. Clean up

Remove bridges (kotlinx-coroutines-rx3, asLiveData()), unused Android-only libraries, dead DI bindings and any AGP opt-outs left in gradle.properties. Re-run kmp-module-health on :shared.

Quick reference

Rule Why
Android shippable after every merge The migration never blocks a release
App module stays Android-only; shared code in its own module AGP 9 rejects KMP + com.android.application
Shared module on com.android.kotlin.multiplatform.library + kotlin { android { } } androidTarget() is deprecated in Kotlin 2.5 and leaves with AGP 10
iOS slice in the first few steps Toolchain, framework and Swift-interop problems surface while cheap
Inward-out: domain → data → presentation → UI Each layer depends only on layers already shared
Same package names when moving files No import churn in the Android app
Interface + platform impl when no KMP library exists Never block on a missing library
Old and new implementations behind one interface Switch the DI binding, not the callers

Verify

Run after each step. Report each check as PASS, FAIL or NOT RUN with the reason (for example "NOT RUN — no macOS host"). Never mark a check PASS that you did not run.

./gradlew help                                        # configures; read any AGP/KGP deprecation warnings
./gradlew :shared:compileCommonMainKotlinMetadata
./gradlew :shared:compileAndroidMain
./gradlew :shared:testAndroidHostTest                 # needs withHostTest {}
./gradlew :shared:iosSimulatorArm64Test               # macOS
./gradlew :shared:linkDebugFrameworkIosSimulatorArm64 # macOS
./gradlew :androidApp:assembleRelease                 # or :app:assembleRelease — Android still shippable
./gradlew :androidApp:testDebugUnitTest               # existing Android tests still pass
grep -rlE '^import (android|java\.time|io\.reactivex|com\.google\.gson|retrofit2)\.' shared/src/commonMain   # expect no output
grep -nE 'androidTarget\(|androidLibrary *\{|com\.android\.library|debugImplementation' shared/build.gradle.kts  # expect no output
grep -rn 'BuildConfig' shared/src                     # expect no output
xcodebuild -project iosApp/iosApp.xcodeproj -scheme iosApp \
  -destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO build                  # macOS

Then kmp-build-check before each PR.

Common mistakes

Mistake Why it bites Fix
Big-bang branch Months of conflicts; Android releases freeze Small PRs to main; Android shippable each time
iOS left until "the shared code is done" Interop, toolchain and API-shape problems found after the investment Vertical slice in step 4
Moving UI first Drags every layer below it along at once Domain → data → presentation → UI
KMP plugin added to the com.android.application module Not supported on AGP 9; the build fails Separate :shared library module; the app depends on it
New :shared on androidTarget() + com.android.library Deprecated in Kotlin 2.5 for every AGP version; works on AGP 9 only behind opt-outs AGP 10 removes com.android.kotlin.multiplatform.library + kotlin { android { } }
Google's agp-9-upgrade run on the KMP module It states it is not for KMP projects Use it on the Android app only; kotlin-tooling-agp9-migration for KMP modules
org.jetbrains.kotlin.android kept in the app on AGP 9 Deprecated in Kotlin 2.5; conflicts with built-in Kotlin Remove it
Keeping kapt for Hilt/Room on AGP 9 Incompatible with AGP's built-in Kotlin KSP (or com.android.legacy-kapt as a stopgap)
BuildConfig read in shared code The Android-KMP plugin generates none; iOS has none either Config interface implemented by the app and bound in DI
debugImplementation for preview tooling in :shared No build types, so no debug configuration "androidRuntimeClasspath"(...)
App and :shared share a namespace Generated classes collide com.example.app for the app, com.example.app.shared for shared
New UIKit iOS host without scene lifecycle Apps without UIScene do not launch when built with the iOS 27 SDK SwiftUI App, or a UIWindowSceneDelegate + scene manifest
@Inject / Hilt annotations in commonMain Hilt is JVM/Android-only; iOS cannot compile it Plain constructors; provide them from an Android Hilt module
Gson → kotlinx.serialization without payload tests Unknown keys and missing fields now throw ignoreUnknownKeys, defaults, tests on captured JSON
Room DAO functions left blocking Non-Android targets require suspend or Flow; Room 3 has no blocking DAOs at all Convert DAOs while moving them
KSP for Room added only to kspAndroid iOS has no generated database code: the build fails on the missing actual, or construction fails at runtime KSP on every declared target
Exporting the whole shared API to Swift Bigger framework, slower links, awkward Swift surface Export only what Swift needs; design that API for Swift
Copying files instead of moving them Two diverging copies of the same logic Move, keep the package, delete the original

Related skills

Files (kmp-mobile-skills)
  • references
    • library-swap.md 9.1 KB
      Loading…
  • SKILL.md 22.8 KB
    ---
    name: android-to-kmp-migration
    description: Use when an existing Android app (Kotlin, Jetpack, Views or Compose) should share code with iOS through Kotlin Multiplatform - "migrate to KMP", "add iOS to our Android app", "make this module multiplatform", "create a shared module", splitting an androidApp entry module from shared code, Retrofit/Gson/Hilt/RxJava/Glide/SharedPreferences/java.time/BuildConfig with no iOS equivalent, or an incremental migration plan. Not for moving a project that is already KMP to AGP 9 (kotlin-tooling-agp9-migration).
    license: Apache-2.0
    compatibility: Existing Android Gradle project in Kotlin. Targets AGP 9.x with the Android-KMP library plugin, Kotlin 2.5 (Gradle 8.14-9.8.1, compiler on JDK 17) and Compose Multiplatform 1.13. iOS steps need macOS with Xcode. Library and toolchain statements checked December 2026.
    metadata:
      category: migration
      platforms: android, ios
    ---
    
    # Android to Kotlin Multiplatform migration
    
    Migrate in thin, shippable slices: create a shared module, prove one vertical slice runs on iOS
    early, then move code inward-out — domain, data, presentation, and only then (optionally) UI. The
    Android app must be releasable after every merged step. A migration that lives on a long branch, or
    that leaves iOS until the end, is where these projects stall.
    
    The target is the AGP 9 layout: the Android app stays a plain Android **entry module** (`:androidApp`,
    or the existing `:app`), and shared code lives in a separate KMP module on
    `com.android.kotlin.multiplatform.library` with `kotlin { android { } }`. Never apply the Kotlin
    Multiplatform plugin to the app module.
    
    ## When to use
    
    - An Android app needs an iOS version and the team wants to share business logic.
    - A module or package should become multiplatform without rewriting the app.
    - Deciding which Android libraries to replace, keep, or hide behind interfaces.
    - Estimating and sequencing the migration for a team.
    
    ## When not to use
    
    - The project is already KMP and only needs AGP 9 (`androidTarget()` to the Android-KMP plugin, app
      module split): JetBrains'
      [`kotlin-tooling-agp9-migration`](https://github.com/Kotlin/kotlin-agent-skills/tree/main/skills/kotlin-tooling-agp9-migration).
    - Upgrading the pure-Android app module to AGP 9 (built-in Kotlin, new DSL, kapt): Google's
      [`agp-9-upgrade`](https://github.com/android/skills/tree/main/build-system/agp/agp-9-upgrade).
      It says it is not for KMP projects, so use it on the Android app **before** `:shared` exists, or
      on the app module only.
    - Converting Java sources to Kotlin first: JetBrains'
      [`kotlin-tooling-java-to-kotlin`](https://github.com/Kotlin/kotlin-agent-skills/tree/main/skills/kotlin-tooling-java-to-kotlin), then return.
    - Adding one new feature module to a project that is already KMP: use `kmp-feature-module`.
    - One `expect`/`actual` pair: use `kmp-expect-actual`.
    
    ## Step 0 — Read the project first
    
    ```bash
    cat settings.gradle.kts; find . -name build.gradle.kts -not -path '*/build/*' | sort
    sed -n '1,80p' gradle/libs.versions.toml               # Kotlin, AGP, Compose, library versions
    cat gradle/wrapper/gradle-wrapper.properties gradle.properties
    grep -rnE 'kotlin\("kapt"\)|kotlin-kapt|org.jetbrains.kotlin.kapt' --include='*.kts' .   # kapt users
    grep -rnE 'org.jetbrains.kotlin.android|kotlin\("android"\)|kotlinAndroid' --include='*.kts' .  # pre-AGP-9 Kotlin plugin
    grep -rnE 'enableLegacyVariantApi|builtInKotlin|newDsl' gradle.properties   # AGP 9 opt-outs in use
    grep -rhoE '^import (android|androidx|dagger|javax\.inject|io\.reactivex|com\.google\.gson|com\.squareup\.(retrofit2|moshi)|com\.bumptech|java\.time|timber)[.a-z]*' \
      --include='*.kt' app/src/main | sort | uniq -c | sort -rn | head -40   # what the code leans on
    grep -rlE 'BuildConfig\.' --include='*.kt' . | head                     # config that must be injected later
    find . -path '*/src/main/java' -o -path '*/src/main/kotlin' | head     # source roots per module
    ls app/src/main/res/layout 2>/dev/null | wc -l                         # View-based UI size
    ```
    
    Record: modules and their dependencies, Kotlin/AGP/Gradle versions, DI framework, async style
    (coroutines, RxJava, LiveData), networking, persistence, image loading, logging, UI toolkit
    (Views, Compose, mixed), test style, whether `kapt` and `BuildConfig` are in use, and which
    `gradle.properties` opt-outs exist. Ask the team two decisions before planning:
    
    1. **iOS UI:** Compose Multiplatform (share UI too) or native SwiftUI over shared logic?
    2. **DI:** move the shared graph to a KMP DI library, or keep Hilt in the Android app and build the
       iOS graph separately?
    
    ## Target layout
    
    ```text
    settings.gradle.kts    include(":androidApp", ":shared")   # keep ":app" if that is the existing name
    androidApp/            com.android.application (+ Compose compiler plugin if Compose)
      src/main/            Application, Activities, manifest, signing, flavours, BuildConfig
    shared/                org.jetbrains.kotlin.multiplatform + com.android.kotlin.multiplatform.library
      src/commonMain/  src/androidMain/  src/iosMain/  src/commonTest/  src/androidHostTest/
    iosApp/                Xcode project; SwiftUI App or UIKit with UIScene lifecycle
    ```
    
    What changes from a pre-AGP-9 KMP template:
    
    | Old pattern | Status | Use instead |
    |---|---|---|
    | KMP plugin + `com.android.application` in one module | Not supported with AGP 9 | Separate Android entry module depending on `:shared` |
    | `androidTarget()` + `com.android.library` | Deprecated in Kotlin 2.5 for every AGP version; on AGP 9 only behind legacy opt-outs that AGP 10 removes | `com.android.kotlin.multiplatform.library` + `kotlin { android { } }` |
    | `kotlin { androidLibrary { } }` | Deprecated since AGP 9.1.0-alpha09 | `kotlin { android { } }` (AGP 8.12+) |
    | `org.jetbrains.kotlin.android` in the app | Deprecated in Kotlin 2.5; AGP 9 compiles Kotlin itself | Remove the plugin (built-in Kotlin) |
    | `debugImplementation(ui-tooling)` in the shared module | The plugin has no build types | `"androidRuntimeClasspath"(...)` (AGP 9.0.0-beta01+) |
    | `BuildConfig` read from shared code | Not generated by the Android-KMP plugin | Config interface injected from the app; or BuildKonfig |
    | `src/main`, `src/test`, `src/androidTest` in the shared module | Not read by the new plugin | `src/androidMain`, `src/androidHostTest`, `src/androidDeviceTest` |
    | `kapt` | Incompatible with AGP 9 built-in Kotlin | KSP, or `com.android.legacy-kapt` as a stopgap |
    
    ## Workflow
    
    Write the plan with `mobile-feature-plan` (one phase per step below), then execute it with
    `mobile-feature-implement`. Each step ends with the Android release build and tests green.
    
    ### 1. Assess and classify
    
    For each package or module, put it in one bucket:
    
    | Bucket | Signal | Action |
    |---|---|---|
    | Pure Kotlin | no `android.*`, `java.*` (other than trivial), or Android-only library imports | Moves to `commonMain` as is |
    | Android API at the edges | `Context`, `SharedPreferences`, `ConnectivityManager`, file paths, `Build`, `BuildConfig` | Interface or `expect`/`actual`; Android impl moves to `androidMain` or the app |
    | Android-only library | Retrofit, Gson, Hilt annotations, RxJava, Glide, Timber, `java.time` | Swap per [references/library-swap.md](references/library-swap.md), or hide behind an interface |
    | UI | Activities, Fragments, XML, Compose screens | Last; optional |
    
    Summary of the library swaps (details, caveats and per-library notes in the reference):
    
    | Android | KMP |
    |---|---|
    | Retrofit + OkHttp | Ktor client (OkHttp engine on Android, Darwin on iOS) |
    | Gson / Moshi | kotlinx.serialization |
    | Room 2 | Room 3 (`androidx.room3`) for new KMP code, or Room 2.8 KMP artifacts — `kmp-room-database` |
    | Hilt / Dagger | Koin 4 (Compiler Plugin optional — `kmp-koin-di`), kotlin-inject or Metro; or keep Hilt in the Android app only |
    | `java.time` | kotlinx-datetime + `kotlin.time.Instant` / `kotlin.time.Clock` |
    | RxJava | coroutines + Flow (bridge with `kotlinx-coroutines-rx3`) |
    | LiveData | `StateFlow` |
    | androidx ViewModel | androidx lifecycle-viewmodel (KMP artifacts) |
    | Glide | Coil 3 |
    | SharedPreferences | DataStore Preferences (KMP) |
    | Timber | Kermit or Napier |
    | `BuildConfig` fields | An `AppConfig` interface the app implements and binds in DI |
    
    Done when: every package has a bucket and every Android-only dependency has a decision.
    
    ### 2. Prepare the build
    
    - Align versions with the
      [Kotlin Multiplatform compatibility guide](https://kotlinlang.org/docs/multiplatform/multiplatform-compatibility-guide.html).
      Kotlin 2.5 needs AGP 8.8.2+, Gradle 8.14–9.8.1 and a JDK 17 runtime for the compiler; AGP 9 needs
      Gradle 9.1+.
    - **Move the Android app to AGP 9 first**, while it is still Android-only: built-in Kotlin (drop
      `org.jetbrains.kotlin.android`), the new DSL, `kapt` to KSP, and removal of `gradle.properties`
      opt-outs. Google's `agp-9-upgrade` skill covers exactly this for a pure-Android build.
    - If the app module itself must stay on AGP 8 for now, still create `:shared` on the Android-KMP
      plugin (it needs AGP 8.10+; use `android { }` from 8.12, `androidLibrary { }` below that). Do not
      start new shared code on `androidTarget()`.
    - Move hardcoded dependency versions into `gradle/libs.versions.toml` (`kmp-gradle-version-catalog`).
    
    Done when: the Android app builds and releases on the target Kotlin/AGP versions, unchanged.
    
    ### 3. Create `:shared` and ship it empty
    
    ```toml
    # gradle/libs.versions.toml — reuse the project's existing version keys
    [plugins]
    kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
    android-kotlin-multiplatform-library = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" }
    # Usually present already for the app; add only if missing.
    android-application = { id = "com.android.application", version.ref = "agp" }
    compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
    ```
    
    ```kotlin
    // shared/build.gradle.kts
    plugins {
        alias(libs.plugins.kotlin.multiplatform)
        alias(libs.plugins.android.kotlin.multiplatform.library)
    }
    
    kotlin {
        android {                       // not androidTarget(); not androidLibrary { } (deprecated)
            namespace = "com.example.app.shared"   // must differ from the app's namespace
            compileSdk = libs.versions.android.compileSdk.get().toInt()
            minSdk = libs.versions.android.minSdk.get().toInt()
            withHostTest { }            // off by default; enables src/androidHostTest
            // androidResources { enable = true }  — add when shared code uses res/ or Compose resources
        }
        listOf(iosArm64(), iosSimulatorArm64()).forEach { target ->   // add iosX64() only if Intel simulators matter
            target.binaries.framework {
                baseName = "Shared"
                isStatic = true
            }
        }
        sourceSets {
            commonMain.dependencies {
                implementation(libs.kotlinx.coroutines.core)
            }
            commonTest.dependencies {
                implementation(libs.kotlin.test)
            }
        }
    }
    ```
    
    The app module stays an Android application and only gains a dependency:
    
    ```kotlin
    // androidApp/build.gradle.kts (or the existing app/build.gradle.kts)
    plugins {
        alias(libs.plugins.android.application)
        alias(libs.plugins.compose.compiler)   // only if the app uses Compose
        // No org.jetbrains.kotlin.android and no Kotlin Multiplatform plugin: AGP 9 compiles Kotlin.
    }
    
    dependencies {
        implementation(project(":shared"))
    }
    ```
    
    Add `include(":shared")` to `settings.gradle.kts` and the new plugins with `apply false` in the root
    build file. Merge this alone. Other opt-ins of the Android-KMP plugin (`withDeviceTest {}`,
    `withJava()`, consumer keep rules) are listed in `kmp-feature-module`.
    
    Done when: `:androidApp` (or `:app`) builds a release with `:shared` on its classpath, and
    `./gradlew :shared:iosSimulatorArm64Test` runs on macOS.
    
    ### 4. Bring up an iOS vertical slice early
    
    Before moving much code, prove the iOS path end to end:
    
    1. Create the iOS app (the KMP wizard's `iosApp`, or an Xcode project) and integrate the framework —
       direct integration runs `./gradlew :shared:embedAndSignAppleFrameworkForXcode` from an Xcode build
       phase; SPM integration is the alternative (`kmp-xcframework-distribution`).
    2. **Use scene lifecycle from day one.** Apple (WWDC26 session 278): "UIScene lifecycle is now
       required when building with the latest SDKs." A SwiftUI `@main App` already uses scenes. A UIKit
       host needs a `UIWindowSceneDelegate` and a scene manifest, not a window built in `AppDelegate`.
    3. Call one shared function from Swift, then one real use case that does I/O (for example "load the
       current user's profile" through the shared repository).
    4. Check Swift ergonomics on that slice: `suspend` functions, `Flow`, sealed classes and default
       arguments are where Swift friction appears (`kmp-swiftui-interop`, which also covers Swift export).
    
    Done when: the iOS app shows real data from shared code on a simulator, built from a clean checkout.
    
    ### 5. Move the domain
    
    Move models, validators, use cases and pure business rules to `commonMain`. Keep the **same package
    names** so Android imports do not change. Replace `java.time` with kotlinx-datetime plus
    `kotlin.time.Instant` / `Clock` (kotlinx-datetime 0.7+ deprecates its own `Instant`), `java.util.UUID`
    with `kotlin.uuid.Uuid` (check whether your Kotlin version still needs an opt-in), and
    `String.format` with string templates. Move their unit tests to `commonTest` so they run on both
    platforms.
    
    Done when: domain tests pass in `testAndroidHostTest` and `iosSimulatorArm64Test`; Android release builds.
    
    ### 6. Move the data layer
    
    One data source at a time, behind the repository interface the app already uses:
    
    - Networking: Ktor + kotlinx.serialization in `commonMain`; per-platform engines. Keep the Retrofit
      implementation bound in Android DI until the Ktor one passes the same tests, then switch the
      binding and delete the old one.
    - Persistence: Room 3 (`androidx.room3`) for a new shared database, or Room 2.8 KMP when the team
      wants to keep the `androidx.room` package for now; SQLDelight if the team prefers. Key-value with
      DataStore. Setup, KSP per target and the Room 2 to Room 3 move are in `kmp-room-database`.
    - DI for the shared graph: `kmp-koin-di` (Koin 4, optionally with the Koin Compiler Plugin for
      build-time graph checks), or keep Hilt in the app.
    - Config: replace `BuildConfig` reads with an interface in `commonMain` that the app implements from
      its own `BuildConfig` and binds in DI.
    - Platform pieces (connectivity, file paths, secure storage) behind interfaces with
      `androidMain`/`iosMain` implementations (`kmp-expect-actual`, `kmp-secure-storage`).
    
    Done when: each repository has one implementation in `commonMain`, tested with fakes, used by Android.
    
    ### 7. Move presentation (ViewModels)
    
    Use androidx `lifecycle-viewmodel` in `commonMain`. Replace `LiveData` with `StateFlow` (Android
    screens can collect it, or bridge with `asLiveData()` temporarily). Inject dispatchers. Android
    Fragments/Compose screens keep working against the same ViewModels; the iOS app consumes them
    through a Swift wrapper.
    
    Done when: ViewModel tests run on both platforms and both apps use the shared ViewModels for the
    migrated features.
    
    ### 8. Optionally move UI to Compose Multiplatform
    
    Only if the team chose shared UI. View-based screens go to Jetpack Compose first, in the Android app,
    with Google's
    [`migrate-xml-views-to-jetpack-compose`](https://github.com/android/skills/tree/main/jetpack-compose/migration/migrate-xml-views-to-jetpack-compose)
    skill. Then the Compose code moves to `commonMain`: replace `R.string`/`R.drawable` with Compose
    Multiplatform resources (the shared module needs `androidResources { enable = true }`), Android-only
    Compose APIs with multiplatform equivalents, and Coil 2/Glide with Coil 3. Preview tooling goes on
    `"androidRuntimeClasspath"(...)`. `MainActivity` stays in the app module. Migrate screen by screen
    behind the existing navigation.
    
    ### 9. Clean up
    
    Remove bridges (`kotlinx-coroutines-rx3`, `asLiveData()`), unused Android-only libraries, dead DI
    bindings and any AGP opt-outs left in `gradle.properties`. Re-run `kmp-module-health` on `:shared`.
    
    ## Quick reference
    
    | Rule | Why |
    |---|---|
    | Android shippable after every merge | The migration never blocks a release |
    | App module stays Android-only; shared code in its own module | AGP 9 rejects KMP + `com.android.application` |
    | Shared module on `com.android.kotlin.multiplatform.library` + `kotlin { android { } }` | `androidTarget()` is deprecated in Kotlin 2.5 and leaves with AGP 10 |
    | iOS slice in the first few steps | Toolchain, framework and Swift-interop problems surface while cheap |
    | Inward-out: domain → data → presentation → UI | Each layer depends only on layers already shared |
    | Same package names when moving files | No import churn in the Android app |
    | Interface + platform impl when no KMP library exists | Never block on a missing library |
    | Old and new implementations behind one interface | Switch the DI binding, not the callers |
    
    ## Verify
    
    Run after each step. Report each check as `PASS`, `FAIL` or `NOT RUN` with the reason (for example
    "NOT RUN — no macOS host"). Never mark a check PASS that you did not run.
    
    ```bash
    ./gradlew help                                        # configures; read any AGP/KGP deprecation warnings
    ./gradlew :shared:compileCommonMainKotlinMetadata
    ./gradlew :shared:compileAndroidMain
    ./gradlew :shared:testAndroidHostTest                 # needs withHostTest {}
    ./gradlew :shared:iosSimulatorArm64Test               # macOS
    ./gradlew :shared:linkDebugFrameworkIosSimulatorArm64 # macOS
    ./gradlew :androidApp:assembleRelease                 # or :app:assembleRelease — Android still shippable
    ./gradlew :androidApp:testDebugUnitTest               # existing Android tests still pass
    grep -rlE '^import (android|java\.time|io\.reactivex|com\.google\.gson|retrofit2)\.' shared/src/commonMain   # expect no output
    grep -nE 'androidTarget\(|androidLibrary *\{|com\.android\.library|debugImplementation' shared/build.gradle.kts  # expect no output
    grep -rn 'BuildConfig' shared/src                     # expect no output
    xcodebuild -project iosApp/iosApp.xcodeproj -scheme iosApp \
      -destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO build                  # macOS
    ```
    
    Then `kmp-build-check` before each PR.
    
    ## Common mistakes
    
    | Mistake | Why it bites | Fix |
    |---|---|---|
    | Big-bang branch | Months of conflicts; Android releases freeze | Small PRs to main; Android shippable each time |
    | iOS left until "the shared code is done" | Interop, toolchain and API-shape problems found after the investment | Vertical slice in step 4 |
    | Moving UI first | Drags every layer below it along at once | Domain → data → presentation → UI |
    | KMP plugin added to the `com.android.application` module | Not supported on AGP 9; the build fails | Separate `:shared` library module; the app depends on it |
    | New `:shared` on `androidTarget()` + `com.android.library` | Deprecated in Kotlin 2.5 for every AGP version; works on AGP 9 only behind opt-outs AGP 10 removes | `com.android.kotlin.multiplatform.library` + `kotlin { android { } }` |
    | Google's `agp-9-upgrade` run on the KMP module | It states it is not for KMP projects | Use it on the Android app only; `kotlin-tooling-agp9-migration` for KMP modules |
    | `org.jetbrains.kotlin.android` kept in the app on AGP 9 | Deprecated in Kotlin 2.5; conflicts with built-in Kotlin | Remove it |
    | Keeping `kapt` for Hilt/Room on AGP 9 | Incompatible with AGP's built-in Kotlin | KSP (or `com.android.legacy-kapt` as a stopgap) |
    | `BuildConfig` read in shared code | The Android-KMP plugin generates none; iOS has none either | Config interface implemented by the app and bound in DI |
    | `debugImplementation` for preview tooling in `:shared` | No build types, so no debug configuration | `"androidRuntimeClasspath"(...)` |
    | App and `:shared` share a namespace | Generated classes collide | `com.example.app` for the app, `com.example.app.shared` for shared |
    | New UIKit iOS host without scene lifecycle | Apps without UIScene do not launch when built with the iOS 27 SDK | SwiftUI `App`, or a `UIWindowSceneDelegate` + scene manifest |
    | `@Inject` / Hilt annotations in `commonMain` | Hilt is JVM/Android-only; iOS cannot compile it | Plain constructors; provide them from an Android Hilt module |
    | Gson → kotlinx.serialization without payload tests | Unknown keys and missing fields now throw | `ignoreUnknownKeys`, defaults, tests on captured JSON |
    | Room DAO functions left blocking | Non-Android targets require `suspend` or `Flow`; Room 3 has no blocking DAOs at all | Convert DAOs while moving them |
    | KSP for Room added only to `kspAndroid` | iOS has no generated database code: the build fails on the missing `actual`, or construction fails at runtime | KSP on every declared target |
    | Exporting the whole shared API to Swift | Bigger framework, slower links, awkward Swift surface | Export only what Swift needs; design that API for Swift |
    | Copying files instead of moving them | Two diverging copies of the same logic | Move, keep the package, delete the original |
    
    ## Related skills
    
    - `mobile-feature-plan`, `mobile-feature-implement` — plan and execute each migration step.
    - `kmp-feature-module`, `kmp-expect-actual`, `kmp-gradle-version-catalog` — module and build mechanics,
      including every Android-KMP plugin opt-in.
    - `kmp-data-layer`, `kmp-api-endpoint`, `kmp-room-database` (Room 3), `kmp-secure-storage`,
      `kmp-koin-di` (Koin Compiler Plugin) — data-layer targets.
    - `kmp-swiftui-interop`, `kmp-xcframework-distribution` — the iOS side of the slice.
    - `compose-multiplatform-screen`, `compose-multiplatform-localization` — if UI moves too.
    - `kmp-ci-github-actions` — add the macOS job as soon as `:shared` exists.
    - External skills (linked, not bundled):
      [`kotlin-tooling-agp9-migration`](https://github.com/Kotlin/kotlin-agent-skills/tree/main/skills/kotlin-tooling-agp9-migration) (JetBrains, KMP modules) ·
      [`kotlin-tooling-java-to-kotlin`](https://github.com/Kotlin/kotlin-agent-skills/tree/main/skills/kotlin-tooling-java-to-kotlin) (JetBrains) ·
      [`agp-9-upgrade`](https://github.com/android/skills/tree/main/build-system/agp/agp-9-upgrade) (Google, Android host module only) ·
      [`migrate-xml-views-to-jetpack-compose`](https://github.com/android/skills/tree/main/jetpack-compose/migration/migrate-xml-views-to-jetpack-compose) (Google).
    - Docs: [Updating KMP projects to AGP 9](https://kotlinlang.org/docs/multiplatform/multiplatform-project-agp-9-migration.html) ·
      [Android-KMP library plugin](https://developer.android.com/kotlin/multiplatform/plugin) ·
      [What's new in Kotlin 2.5.0](https://kotlinlang.org/docs/whatsnew25.html) ·
      [Make your Android application work on iOS](https://kotlinlang.org/docs/multiplatform/multiplatform-integrate-in-existing-app.html) ·
      [Migrating a Jetpack Compose app to KMP](https://kotlinlang.org/docs/multiplatform/migrate-from-android.html) ·
      [Add KMP to an existing project](https://developer.android.com/kotlin/multiplatform/migrate).
    

Comments

Sign in to join the conversation.

No comments yet. Start the conversation.

Reviews (0)

No reviews yet.