npx skills add ...
npx skills add kotlin/kotlin-agent-skills --skill kotlin-tooling-agp9-migration
npx skills add kotlin/kotlin-agent-skills --skill kotlin-tooling-agp9-migration
Migrates Kotlin Multiplatform (KMP) projects to Android Gradle Plugin 9.0+. Handles plugin replacement (com.android.kotlin.multiplatform.library), module splitting, DSL migration, and the new default project structure. Use when upgrading AGP, when build fails due to KMP+AGP incompatibility, or when the user mentions AGP 9.0, android multiplatform plugin, KMP migration, or com.android.kotlin.multiplatform.library.
Android Gradle Plugin 9.0 makes the Android application and library plugins incompatible with the Kotlin Multiplatform plugin in the same module. This skill guides you through the migration.
Before making any changes, understand the project structure:
settings.gradle.kts (or .gradle) to find all modulesbuild.gradle.kts to identify which plugins are appliedgradle/libs.versions.toml). If it exists,
read it for current AGP/Gradle/Kotlin versions. If not, find versions directly in build.gradle.kts
files (typically in the root buildscript {} or plugins {} block). Adapt all examples in this
guide accordingly — version catalog examples use alias(libs.plugins.xxx) while direct usage
uses id("plugin.id") version "x.y.z"gradle/wrapper/gradle-wrapper.properties for the Gradle versiongradle.properties for any existing workarounds (android.enableLegacyVariantApi)org.jetbrains.kotlin.android plugin usage — AGP 9.0 has built-in Kotlin and this plugin must be removedorg.jetbrains.kotlin.kapt plugin usage — incompatible with built-in Kotlin, must migrate to KSP or com.android.legacy-kaptIf Bash is available, run scripts/analyze-project.sh from this skill's directory to get a structured summary.
For each module, determine its type:
| Current plugins | Migration path |
|---|---|
kotlin.multiplatform + com.android.library | Path A — Library plugin swap |
kotlin.multiplatform + com.android.application | Path B — Mandatory Android split |
kotlin.multiplatform with multiple platform entry points in one module | Path C — Full restructure (recommended) |
com.android.application or com.android.library (no KMP) | See "Pure Android Tips" below |
composeApp (or similar) module
containing entry points for multiple platforms (Android, Desktop, Web). This aligns with the
new JetBrains default project structure where each platform gets its own app module.Use this when a module applies kotlin.multiplatform + com.android.library.
See references/MIGRATION-LIBRARY.md for full before/after code.
Summary:
com.android.library → com.android.kotlin.multiplatform.libraryorg.jetbrains.kotlin.android plugin if present (AGP 9.0 has built-in Kotlin support)android {} block into kotlin { android {} }:
src/main → src/androidMainsrc/test → src/androidHostTestsrc/androidTest → src/androidDeviceTestsrc/androidMain/, no directory renames are neededdependencies {} into sourceSets:
.java source files:
debug/release build types, or product flavors like free/paid). Configure fallback behaviors using localDependencySelection:
Use this when a module applies kotlin.multiplatform + com.android.application. This is mandatory for AGP 9.0 compatibility.
See references/MIGRATION-APP-SPLIT.md for full guide.
Summary:
androidApp module with its own build.gradle.kts:
src/androidMain/ to androidApp/src/main/:
MainActivity.kt (and any other Activities/Fragments)AndroidManifest.xml (app-level manifest with <application> and launcher <activity>) — verify android:name on <activity> uses the fully qualified class name in its new locationsettings.gradle.kts: include(":androidApp")build.gradle.kts: plugin declarations with apply falseapplicationId, targetSdk, versionCode, versionNameandroidAppUse this when the project has a monolithic module (typically composeApp) containing entry
points for multiple platforms. This is optional but aligns with the new JetBrains default.
See references/MIGRATION-FULL-RESTRUCTURE.md for full guide.
androidApp (mandatory for AGP 9.0)desktopApp (if desktop target exists):
org.jetbrains.compose and application {} pluginmain() function from desktopMain to desktopApp/src/main/kotlin/compose.desktop { application { ... } } config to desktopApp/build.gradle.ktsshared modulewebApp (if wasmJs/js target exists):
wasmJsMain/jsMain to webApp/src/wasmJsMain/kotlin/webApp/build.gradle.ktsshared moduleiosApp directory. Verify:
binaries.framework) stays in shared modulecomposeApp to shared:
settings.gradle.kts includeIf some platforms use native UI (e.g., SwiftUI for iOS), split shared into:
sharedLogic — business logic consumed by ALL platformssharedUI — Compose Multiplatform UI consumed only by platforms using shared UIIf the project includes a server target:
server module at the rootapp/ directorycore module for code shared between server and client (models, validation)These are required regardless of migration path:
Gradle wrapper — update to 9.1.0+:
AGP version — update to 9.0.0+ and add the KMP library plugin.
With version catalog (gradle/libs.versions.toml):
Without version catalog — update com.android.* plugin versions and add in root build.gradle.kts:
JDK — ensure JDK 17+ is used (required by AGP 9.0)
SDK Build Tools — update to 36.0.0:
Review gradle.properties — remove error-causing properties and review changed defaults (see "Gradle Properties Default Changes" section)
AGP 9.0 enables built-in Kotlin support by default for all com.android.application and com.android.library
modules. The org.jetbrains.kotlin.android plugin is no longer needed and will conflict if applied.
Important: Built-in Kotlin does NOT replace KMP support. KMP library modules still need
org.jetbrains.kotlin.multiplatform + com.android.kotlin.multiplatform.library.
Remove from all module-level and root-level build files:
Remove from version catalog (gradle/libs.versions.toml):
The org.jetbrains.kotlin.kapt plugin is incompatible with built-in Kotlin.
Preferred: Migrate to KSP — see the KSP migration guide for each annotation processor.
Fallback: Use com.android.legacy-kapt (same version as AGP):
For pure Android modules (non-KMP), migrate android.kotlinOptions {} to the top-level
kotlin.compilerOptions {}:
Note: With built-in Kotlin, jvmTarget defaults to android.compileOptions.targetCompatibility, so it may be optional if you already set compileOptions.
With built-in Kotlin, only android.sourceSets {} with the kotlin set is supported:
For generated sources, use the Variant API:
For large projects, migrate module-by-module:
android.builtInKotlin=false in gradle.propertiesandroid.builtInKotlin=false and all com.android.built-in-kotlin pluginsFor modules that contain no Kotlin sources, disable built-in Kotlin to save build time:
If blocked by plugin incompatibilities, opt out temporarily:
Warning: Ask the user if they want to opt out, and if so, remind them this is a temporary measure.
See references/PLUGIN-COMPATIBILITY.md for the full compatibility table with known compatible versions, opt-out flag workarounds, and broken plugins.
Before migrating, inventory all plugins in the project and check each against that table. If any plugin is broken without workaround, inform the user. If plugins need opt-out flags, add them togradle.properties and note them as temporary workarounds.
AGP 9.0 changes the defaults for many Gradle properties. Check gradle.properties for any explicitly set values that may now conflict.
Key changes:
| Property | Old Default | New Default | Action |
|---|---|---|---|
android.uniquePackageNames | false | true | Ensure each library has a unique namespace |
android.enableAppCompileTimeRClass | false | true | Refactor switch on R fields to if/else |
android.defaults.buildfeatures.resvalues | true | false | Enable resValues = true where needed |
android.defaults.buildfeatures.shaders | true | false | Enable shaders where needed |
android.r8.optimizedResourceShrinking | false | true | Review R8 keep rules |
android.r8.strictFullModeForKeepRules | false | true | Update keep rules to be explicit |
android.proguard.failOnMissingFiles | false | true | Remove invalid ProGuard file references |
android.r8.proguardAndroidTxt.disallowed | false | true | Use proguard-android-optimize.txt only |
android.r8.globalOptionsInConsumerRules.disallowed | false | true | Remove global options from library consumer rules |
android.sourceset.disallowProvider | false | true | Use Sources API on androidComponents |
android.sdk.defaultTargetSdkToCompileSdkIfUnset | false | true | Specify targetSdk explicitly |
android.onlyEnableUnitTestForTheTestedBuildType | false | true | Only if testing non-default build types |
Check for and remove properties that now cause errors:
android.r8.integratedResourceShrinking — removed, always onandroid.enableNewResourceShrinker.preciseShrinking — removed, always onFor non-KMP Android modules upgrading to AGP 9.0, follow the "Built-in Kotlin Migration" steps above, then review the "Gradle Properties Default Changes" table. Additional changes:
BaseExtension is removed; use CommonExtension or specific extension typescompileOptions reflects thisAfter migration, verify with the checklist. Key checks:
./gradlew build succeeds with no errorsxcodebuild, Desktop, JS/Wasm)./gradlew :shared:allTests and Android unit tests passcom.android.library or com.android.application in KMP modulesorg.jetbrains.kotlin.android in AGP 9.0 modulesandroidMain, androidHostTest, androidDeviceTest)See references/KNOWN-ISSUES.md for details. Key gotchas:
AppConfiguration interface, or use BuildKonfig or gradle-buildconfig-plugin for compile-time constantscom.android.library moduleandroidResources { enable = true }consumerProguardFiles.add(file(...)) in new DSLCommonExtensionapplicationVariants, libraryVariants, variantFilter replaced by androidComponentsandroid {} extension helpers are obsolete