Kotlin Tooling Agp9 Migration
JetBrainsOfficialCreated by JetBrainsDistributed by JetBrains
- Skill
- Workflow
- Software development
- Apache-2.0
- Low risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
Android Gradle Plugin 9.0 introduces breaking changes for Kotlin Multiplatform (KMP) projects, specifically regarding the incompatibility of the Android application/library plugins with the KMP plugin in the same module. This skill provides a structured migration path to update KMP projects, including replacing plugins with com.android.kotlin.multiplatform.library, splitting monolithic modules into platform-specific app modules, and updating DSL configurations to the new standards required by AGP 9.0.
What it does
- Replaces legacy Android plugins with the new com.android.kotlin.multiplatform.library plugin.
- Guides the mandatory splitting of KMP modules that combine application and library logic.
- Provides a full project restructure path for monolithic modules containing multiple platform entry points.
- Automates the migration of DSL configurations from top-level android blocks to the new kotlin { android {} } structure.
- Assists in removing deprecated plugins like org.jetbrains.kotlin.android and migrating kapt to KSP.
- Updates project-wide settings including Gradle wrappers, JDK requirements, and build tools.
When to use it
- When upgrading an existing KMP project to use Android Gradle Plugin 9.0 or higher.
- When encountering build failures due to incompatibility between KMP and AGP 9.0.
- When refactoring a monolithic KMP project to align with the recommended multi-module structure.
- When needing to remove the deprecated org.jetbrains.kotlin.android plugin in favor of built-in Kotlin support.
Advantages
- Ensures compatibility with the latest Android build system requirements.
- Promotes a cleaner, more modular project architecture.
- Reduces build complexity by leveraging built-in Kotlin support in AGP 9.0.
- Provides clear, step-by-step paths for different project configurations (Library vs. App).
- Includes comprehensive references for DSL mapping and known migration issues.
Usage examples
- “How do I migrate my KMP library module to AGP 9.0?”
- The agent will guide you through Path A, replacing the plugin with com.android.kotlin.multiplatform.library and moving your android {} block into the kotlin {} block.
- “My build fails because I have KMP and the Android application plugin in the same module.”
- The agent will initiate Path B, helping you extract the Android entry point into a separate androidApp module while converting the original module to a library.
- “I need to remove the kotlin-android plugin for AGP 9.0.”
- The agent will provide instructions on removing the plugin from your build files and migrating your compiler options to the new kotlin.compilerOptions DSL.
- “How do I restructure my monolithic composeApp module?”
- The agent will walk you through Path C, splitting your project into dedicated shared, androidApp, and other platform-specific modules.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/jetbrains/kotlin-tooling-agp9-migration/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip kotlin-tooling-agp9-migration.zip -d .agents/skills
Documentation by JetBrains
KMP AGP 9.0 Migration
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.
Step 0: Analyze the Project
Before making any changes, understand the project structure:
Read
settings.gradle.kts(or.gradle) to find all modulesFor each module, read its
build.gradle.ktsto identify which plugins are appliedCheck if the project uses a Gradle version catalog (
gradle/libs.versions.toml). If it exists, read it for current AGP/Gradle/Kotlin versions. If not, find versions directly inbuild.gradle.ktsfiles (typically in the rootbuildscript {}orplugins {}block). Adapt all examples in this guide accordingly — version catalog examples usealias(libs.plugins.xxx)while direct usage usesid("plugin.id") version "x.y.z"Read
gradle/wrapper/gradle-wrapper.propertiesfor the Gradle versionCheck
gradle.propertiesfor any existing workarounds (android.enableLegacyVariantApi)Check for
org.jetbrains.kotlin.androidplugin usage — AGP 9.0 has built-in Kotlin and this plugin must be removedCheck for
org.jetbrains.kotlin.kaptplugin usage — incompatible with built-in Kotlin, must migrate to KSP orcom.android.legacy-kaptCheck for third-party plugins that may be incompatible with AGP 9.0 (see "Plugin Compatibility" section below)
If Bash is available, run scripts/analyze-project.sh from this skill's directory to get a
structured summary.
Classify Each Module
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 |
Determine Scope
Path B is mandatory for any module combining KMP + Android application plugin
Path C is recommended when the project has a monolithic
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.Ask the user whether they want Path B only (minimum required) or Path C (recommended full restructure)
Path A: Library Module Migration
Use this when a module applies kotlin.multiplatform + com.android.library.
See references/MIGRATION-LIBRARY.md for full before/after code.
Summary:
Replace plugin:
com.android.library→com.android.kotlin.multiplatform.libraryRemove
org.jetbrains.kotlin.androidplugin if present (AGP 9.0 has built-in Kotlin support)Migrate DSL: Move config from top-level
android {}block intokotlin { android {} }:kotlin { android { namespace = "com.example.lib" compileSdk = 35 minSdk = 24 } }Rename source directories (only if the module uses classic Android layout instead of KMP layout):
src/main→src/androidMainsrc/test→src/androidHostTestsrc/androidTest→src/androidDeviceTestIf the module already uses
src/androidMain/, no directory renames are needed
Move dependencies from top-level
dependencies {}intosourceSets:kotlin { sourceSets { androidMain.dependencies { implementation("androidx.appcompat:appcompat:1.7.0") } } }Enable resources explicitly if the module uses Android resources:
kotlin { android { androidResources { enable = true } } }Enable Java compilation if module has
.javasource files:kotlin { android { withJava() } }Enable tests explicitly if the module has unit or instrumented tests:
kotlin { android { withHostTest { isIncludeAndroidResources = true } withDeviceTest { instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } } }Update Compose tooling dependency:
// Old: debugImplementation(libs.androidx.compose.ui.tooling) // New: dependencies { androidRuntimeClasspath(libs.androidx.compose.ui.tooling) }Publish consumer ProGuard rules explicitly if applicable:
kotlin { android { consumerProguardFiles.add(file("consumer-rules.pro")) } }
Path B: Android App + Shared Module Split
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:
Create
androidAppmodule with its ownbuild.gradle.kts:plugins { alias(libs.plugins.androidApplication) // Do NOT apply kotlin-android — AGP 9.0 includes Kotlin support alias(libs.plugins.composeMultiplatform) // if using Compose alias(libs.plugins.composeCompiler) // if using Compose } android { namespace = "com.example.app" compileSdk = 35 defaultConfig { applicationId = "com.example.app" minSdk = 24 targetSdk = 35 versionCode = 1 versionName = "1.0" } buildFeatures { compose = true } } dependencies { implementation(projects.shared) // or whatever the shared module is named implementation(libs.androidx.activity.compose) }Move Android entry point code from
src/androidMain/toandroidApp/src/main/:MainActivity.kt(and any other Activities/Fragments)AndroidManifest.xml(app-level manifest with<application>and launcher<activity>) — verifyandroid:nameon<activity>uses the fully qualified class name in its new locationAndroid Application class if present
App-level resources (launcher icons, theme, etc.)
Add to
settings.gradle.kts:include(":androidApp")Add to root
build.gradle.kts: plugin declarations withapply falseConvert original module from application to library using Path A steps
Ensure different namespaces: app module and library module must have distinct namespaces
Remove from shared module:
applicationId,targetSdk,versionCode,versionNameUpdate IDE run configurations: change the module from the old module to
androidApp
Path C: Full Restructure (Recommended)
Use 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.
Target Structure
project/
├── shared/ ← KMP library (was composeApp), pure shared code
├── androidApp/ ← Android entry point only
├── desktopApp/ ← Desktop entry point only (if desktop target exists)
├── webApp/ ← Wasm/JS entry point only (if web target exists)
├── iosApp/ ← iOS Xcode project (usually already separate)
└── ...Steps
Apply Path B first — extract
androidApp(mandatory for AGP 9.0)Extract
desktopApp(if desktop target exists):Create module with
org.jetbrains.composeandapplication {}pluginMove
main()function fromdesktopMaintodesktopApp/src/main/kotlin/Move
compose.desktop { application { ... } }config todesktopApp/build.gradle.ktsAdd dependency on
sharedmodule
Extract
webApp(if wasmJs/js target exists):Create module with appropriate Kotlin/JS or Kotlin/Wasm configuration
Move web entry point from
wasmJsMain/jsMaintowebApp/src/wasmJsMain/kotlin/Move browser/distribution config to
webApp/build.gradle.ktsAdd dependency on
sharedmodule
iOS — typically already in a separate
iosAppdirectory. Verify:Framework export config (
binaries.framework) stays insharedmoduleXcode project references the correct framework path
Rename module from
composeApptoshared:Rename directory
Update
settings.gradle.ktsincludeUpdate all dependency references across modules
Clean up shared module: remove all platform entry point code and app-specific config that was moved to the platform app modules
Variant: Native UI
If 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 UI
Variant: Server
If the project includes a server target:
Add
servermodule at the rootMove all client modules under an
app/directoryAdd
coremodule for code shared between server and client (models, validation)
Version Updates
These are required regardless of migration path:
Gradle wrapper — update to 9.1.0+:
# gradle/wrapper/gradle-wrapper.properties distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zipAGP version — update to 9.0.0+.
If using a version catalog (
gradle/libs.versions.toml):[versions] agp = "9.0.0"If versions are set directly in build files, update all
com.android.*plugin version strings:// root build.gradle.kts plugins { id("com.android.application") version "9.0.0" apply false }Add the KMP library plugin.
With version catalog:
[plugins] android-kotlin-multiplatform-library = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" }Without version catalog — use the plugin ID directly in build files:
// root build.gradle.kts plugins { id("com.android.kotlin.multiplatform.library") version "9.0.0" apply false } // module build.gradle.kts plugins { id("com.android.kotlin.multiplatform.library") }Root build.gradle.kts — add
apply falsefor new plugin (see examples above)JDK — ensure JDK 17+ is used (required by AGP 9.0)
SDK Build Tools — update to 36.0.0:
Install via SDK Manager or configure in android { buildToolsVersion = "36.0.0" }Remove legacy workarounds from
gradle.properties:Remove
android.enableLegacyVariantApi=true(removed in AGP 9.0, causes error if present)Remove
android.r8.integratedResourceShrinking(removed in AGP 9.0, causes error if present)Remove
android.enableNewResourceShrinker.preciseShrinking(removed in AGP 9.0, causes error if present)Remove
android.builtInKotlin=false(unless needed for plugin compatibility — see Plugin Compatibility)Remove
android.newDsl=false(unless needed for plugin compatibility)
Review gradle.properties defaults — see "Gradle Properties Default Changes" section for properties whose defaults changed in AGP 9.0
Built-in Kotlin Migration
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.
Detection
Check if the project uses org.jetbrains.kotlin.android or kotlin-android in any build files.
If found, this migration is needed. If not, check gradle.properties for android.builtInKotlin=false
which may indicate a previous opt-out.
Step 1: Remove kotlin-android Plugin
Remove from all module-level and root-level build files:
// Remove from module build.gradle.kts
plugins {
// REMOVE: alias(libs.plugins.kotlin.android)
// REMOVE: id("org.jetbrains.kotlin.android")
}
// Remove from root build.gradle.kts
plugins {
// REMOVE: alias(libs.plugins.kotlin.android) apply false
}Remove from version catalog (gradle/libs.versions.toml):
[plugins]
# REMOVE: kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }Step 2: Migrate kapt to KSP or legacy-kapt
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):
# gradle/libs.versions.toml
[plugins]
legacy-kapt = { id = "com.android.legacy-kapt", version.ref = "agp" }// Module build.gradle.kts — replace kotlin-kapt with legacy-kapt
plugins {
// REMOVE: alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.legacy.kapt)
}Step 3: Migrate kotlinOptions to compilerOptions
For pure Android modules (non-KMP), migrate android.kotlinOptions {} to the top-level
kotlin.compilerOptions {}:
// Old
android {
kotlinOptions {
jvmTarget = "11"
languageVersion = "2.0"
freeCompilerArgs += listOf("-Xopt-in=kotlin.RequiresOptIn")
}
}
// New
kotlin {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
languageVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0)
optIn.add("kotlin.RequiresOptIn")
}
}Note: With built-in Kotlin, jvmTarget defaults to android.compileOptions.targetCompatibility,
so it may be optional if you already set compileOptions.
Step 4: Migrate kotlin.sourceSets to android.sourceSets
With built-in Kotlin, only android.sourceSets {} with the kotlin set is supported:
// NOT SUPPORTED with built-in Kotlin:
kotlin.sourceSets.named("main") {
kotlin.srcDir("additionalSourceDirectory/kotlin")
}
// Correct:
android.sourceSets.named("main") {
kotlin.directories += "additionalSourceDirectory/kotlin"
}For generated sources, use the Variant API:
androidComponents.onVariants { variant ->
variant.sources.kotlin!!.addStaticSourceDirectory("additionalSourceDirectory/kotlin")
}Per-Module Migration Strategy
For large projects, migrate module-by-module:
Disable globally:
android.builtInKotlin=falseingradle.propertiesEnable per migrated module by applying the opt-in plugin:
plugins { id("com.android.built-in-kotlin") version "AGP_VERSION" }Follow Steps 1-4 for that module
Once all modules are migrated, remove
android.builtInKotlin=falseand allcom.android.built-in-kotlinplugins
Optional: Disable Kotlin for Non-Kotlin Modules
For modules that contain no Kotlin sources, disable built-in Kotlin to save build time:
android {
enableKotlin = false
}Opt-Out (Temporary)
If blocked by plugin incompatibilities, opt out temporarily:
# gradle.properties
android.builtInKotlin=false
android.newDsl=false # also required if using new DSL opt-outWarning: Ask the user if they want to opt out, and if so, remind them this is a temporary measure.
Plugin Compatibility
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 to
gradle.properties and note them as temporary workarounds.
Gradle Properties Default Changes
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 on
Pure Android Tips
For non-KMP Android modules upgrading to AGP 9.0:
Remove
org.jetbrains.kotlin.androidplugin — AGP 9.0 includes Kotlin support built-in (see "Built-in Kotlin Migration" above)Migrate kapt to KSP or
com.android.legacy-kaptMigrate
kotlinOptionstokotlin { compilerOptions {} }Migrate
kotlin.sourceSetstoandroid.sourceSetswith.kotlinaccessorReview new DSL interfaces —
BaseExtensionis removed; useCommonExtensionor specific extension typesJava default changed from Java 8 to Java 11 — ensure
compileOptionsreflects thisR class is now compile-time non-final in app modules — refactor any
switchstatements on R class fields toif/elsetargetSdk defaults to compileSdk if not set — specify
targetSdkexplicitly to avoid surprisesNDK default changed to r28c — specify
ndkVersionexplicitly if using native codeTemporary opt-out:
android.builtInKotlin=false+android.newDsl=falseingradle.properties(removed in AGP 10)
Verification
After migration, verify with the checklist. Key checks:
./gradlew buildsucceeds with no errors./gradlew :androidApp:assembleDebugsucceeds (if app module exists)No
com.android.libraryorcom.android.applicationin KMP modulesNo
org.jetbrains.kotlin.androidin AGP 9.0 modulesSource sets use correct names (
androidMain,androidHostTest,androidDeviceTest)No deprecation warnings about variant API
Run configurations point to correct modules
Common Issues
See references/KNOWN-ISSUES.md for details. Key gotchas:
KMP Library Plugin Issues
BuildConfig unavailable in library modules — use DI/
AppConfigurationinterface, or use BuildKonfig or gradle-buildconfig-plugin for compile-time constantsNo build variants — single variant architecture; compile-time constants can use BuildKonfig/gradle-buildconfig-plugin flavors, but variant-specific dependencies/resources/signing must move to app module
NDK/JNI unsupported in new plugin — extract to separate
com.android.librarymoduleCompose resources crash without
androidResources { enable = true }(CMP-9547)Consumer ProGuard rules silently dropped if not migrated to
consumerProguardFiles.add(file(...))in new DSLKSP requires version 2.3.4+ for AGP 9.0 compatibility
AGP 9.0 General Issues
Built-in Kotlin conflicts —
org.jetbrains.kotlin.androidmust be removed; kapt must be replacedBaseExtension removed — convention plugins using old DSL types need rewriting
Variant APIs removed —
applicationVariants,libraryVariants,variantFilterreplaced byandroidComponentsR class non-final —
switchon R fields fails in app modules; refactor toif/elsetargetSdk defaults to compileSdk — set explicitly to avoid unexpected behavior changes
R8 rule changes — strict full mode, no global options in consumer rules
Plugin compatibility — many plugins need updates or opt-out flags; check Plugin Compatibility section
Convention plugins need refactoring — old
android {}extension helpers are obsolete
Reference Files
DSL Reference — side-by-side old→new DSL mapping
Version Matrix — AGP/Gradle/KGP/IDE compatibility
Plugin Compatibility — third-party plugin status and workarounds
Files
- ATTRIBUTION.mdAdded by AutoGineer1023 B
- LICENSEAdded by AutoGineer10.0 KiB
- SKILL.md21.9 KiB
- assets/checklist.md3.6 KiB
- references/DSL-REFERENCE.md9.7 KiB
- references/KNOWN-ISSUES.md18.1 KiB
- references/MIGRATION-APP-SPLIT.md14.1 KiB
- references/MIGRATION-FULL-RESTRUCTURE.md12.2 KiB
- references/MIGRATION-LIBRARY.md12.6 KiB
- references/PLUGIN-COMPATIBILITY.md2.5 KiB
- references/VERSION-MATRIX.md6.6 KiB
- scripts/analyze-project.shScript8.1 KiB
references/MIGRATION-LIBRARY.md
Migrating a KMP Library Module to AGP 9.0
This reference covers the full migration of a Kotlin Multiplatform library module from com.android.library (AGP 8.x) to com.android.kotlin.multiplatform.library (AGP 9.x).
build.gradle.kts -- Before (AGP 8.x)
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
}
kotlin {
androidTarget {
compilations.all {
kotlinOptions { jvmTarget = "11" }
}
}
iosX64()
iosArm64()
iosSimulatorArm64()
sourceSets {
commonMain.dependencies {
implementation(libs.kotlinx.coroutines.core)
}
androidMain.dependencies {
implementation(libs.androidx.appcompat)
}
}
}
android {
namespace = "com.example.shared"
compileSdk = 34
defaultConfig { minSdk = 24 }
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
dependencies {
debugImplementation(libs.compose.ui.tooling)
}build.gradle.kts -- After (AGP 9.x)
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidKmpLibrary)
}
kotlin {
android {
namespace = "com.example.shared"
compileSdk = 35
minSdk = 24
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
}
androidResources { enable = true }
}
iosX64()
iosArm64()
iosSimulatorArm64()
sourceSets {
commonMain.dependencies {
implementation(libs.kotlinx.coroutines.core)
}
androidMain.dependencies {
implementation(libs.androidx.appcompat)
}
}
}
dependencies {
"androidRuntimeClasspath"(libs.compose.ui.tooling)
}Version and Plugin Changes
With Version Catalog (gradle/libs.versions.toml)
Before:
[versions]
agp = "8.7.3"
kotlin = "2.1.0"
[plugins]
androidLibrary = { id = "com.android.library", version.ref = "agp" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }After:
[versions]
agp = "9.0.1"
kotlin = "2.3.0"
[plugins]
androidKmpLibrary = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }Without Version Catalog
If versions are declared directly in build files, update the plugin IDs and versions in place:
Before (root build.gradle.kts):
plugins {
id("com.android.library") version "8.7.3" apply false
id("org.jetbrains.kotlin.multiplatform") version "2.1.0" apply false
}After (root build.gradle.kts):
plugins {
id("com.android.kotlin.multiplatform.library") version "9.0.1" apply false
id("org.jetbrains.kotlin.multiplatform") version "2.3.0" apply false
}Before (module build.gradle.kts):
plugins {
id("org.jetbrains.kotlin.multiplatform")
id("com.android.library")
}After (module build.gradle.kts):
plugins {
id("org.jetbrains.kotlin.multiplatform")
id("com.android.kotlin.multiplatform.library")
}Key changes:
The plugin ID changes from
com.android.librarytocom.android.kotlin.multiplatform.library.AGP version must be 9.0.0+, Gradle 9.1.0+, KGP 2.0.0+ (2.3.0+ recommended).
Root build.gradle.kts Changes
With Version Catalog
Before:
plugins {
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
}After:
plugins {
alias(libs.plugins.androidKmpLibrary) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
}Without Version Catalog
Before:
plugins {
id("com.android.library") version "8.7.3" apply false
id("org.jetbrains.kotlin.multiplatform") version "2.1.0" apply false
}After:
plugins {
id("com.android.kotlin.multiplatform.library") version "9.0.1" apply false
id("org.jetbrains.kotlin.multiplatform") version "2.3.0" apply false
}No other root-level changes are required unless you have convention plugins that reference the old plugin ID (see convention plugin section below).
Source Directory Renames
The new KMP-integrated plugin does NOT change the expected source directory layout. The standard KMP source sets still apply:
| Source Set | Directory |
|---|---|
commonMain | src/commonMain/kotlin/ |
androidMain | src/androidMain/kotlin/ |
androidMain resources | src/androidMain/res/ |
iosMain | src/iosMain/kotlin/ |
No renames are required if you already use the standard KMP layout. If your module previously used the classic Android layout (src/main/java/, src/main/res/), you must migrate to the KMP layout:
| Old (Android layout) | New (KMP layout) |
|---|---|
src/main/java/ | src/androidMain/kotlin/ |
src/main/res/ | src/androidMain/res/ |
src/main/AndroidManifest.xml | src/androidMain/AndroidManifest.xml |
src/test/java/ | src/androidHostTest/kotlin/ (or src/androidUnitTest/kotlin/) |
src/androidTest/java/ | src/androidDeviceTest/kotlin/ (or src/androidInstrumentedTest/kotlin/) |
Test Configuration
The new plugin uses explicit opt-in for test source sets.
Host Tests (Unit Tests)
kotlin {
android {
// Enable unit tests (JVM-based, run on host machine)
withHostTest {
// Optional: configure the host test compilation
}
}
}This creates the androidHostTest source set. The previous name androidUnitTest still works as an alias but androidHostTest is preferred.
Device Tests (Instrumented Tests)
kotlin {
android {
// Enable instrumented tests (run on device/emulator)
withDeviceTest {
// Optional: configure the device test compilation
}
}
}This creates the androidDeviceTest source set. The previous name androidInstrumentedTest still works as an alias but androidDeviceTest is preferred.
Full Test Example
kotlin {
android {
namespace = "com.example.shared"
compileSdk = 35
minSdk = 24
withHostTest {}
withDeviceTest {}
}
sourceSets {
androidHostTest.dependencies {
implementation(libs.junit)
implementation(libs.robolectric)
}
androidDeviceTest.dependencies {
implementation(libs.androidx.test.runner)
implementation(libs.androidx.test.espresso.core)
}
}
}Java Compilation (withJava)
If your module contains Java source files in androidMain, you must explicitly enable Java compilation:
kotlin {
android {
withJava()
}
}Without this call, .java files in src/androidMain/java/ will be ignored. Kotlin files are compiled by default.
Consumer ProGuard Rules
Before (AGP 8.x)
android {
defaultConfig {
consumerProguardFiles("consumer-rules.pro")
}
}After (AGP 9.x)
kotlin {
android {
consumerProguardFiles.add(file("consumer-rules.pro"))
}
}Warning: Consumer ProGuard rules can be silently dropped during migration if you forget this step. The old android {} block is gone, so the consumerProguardFiles call in defaultConfig has no equivalent location unless you explicitly add it in kotlin { android {} }.
JVM Target Configuration Hierarchy
There are three levels at which you can configure the JVM target. They are listed from most specific (highest priority) to least specific (lowest priority):
Level 1: Android-Specific Compiler Options (Recommended)
kotlin {
android {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
}
}
}This sets the JVM target only for the Android compilation.
Level 2: Top-Level Kotlin Compiler Options
kotlin {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
}
}This sets the JVM target for ALL JVM-based compilations in the project (Android, JVM desktop, etc.).
Level 3: Gradle Toolchain
kotlin {
jvmToolchain(11)
}This sets both the JDK used for compilation and the JVM target. It is the broadest setting and affects all JVM compilations.
Priority Order
If multiple levels are set, the most specific wins:
kotlin { android { compilerOptions { } } }-- highest prioritykotlin { compilerOptions { } }-- medium prioritykotlin { jvmToolchain() }-- lowest priority
Migration from kotlinOptions
The old kotlinOptions DSL is removed:
// REMOVED in AGP 9.0 -- do not use
androidTarget {
compilations.all {
kotlinOptions { jvmTarget = "11" }
}
}Replace with one of the three levels above.
Dependencies Configuration Changes
The top-level dependencies {} block configurations change because build variants (debug/release) are removed from the KMP library plugin.
Before
dependencies {
debugImplementation(libs.compose.ui.tooling)
releaseImplementation(libs.some.lib)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.runner)
}After
dependencies {
// Use string-based configuration names
"androidRuntimeClasspath"(libs.compose.ui.tooling)
// Or use sourceSets for most dependencies
}
kotlin {
sourceSets {
androidMain.dependencies {
implementation(libs.some.lib)
}
androidHostTest.dependencies {
implementation(libs.junit)
}
androidDeviceTest.dependencies {
implementation(libs.androidx.test.runner)
}
}
}Prefer putting dependencies inside sourceSets blocks rather than the top-level dependencies {} block. The top-level block is only needed for special configurations like androidRuntimeClasspath that have no source set equivalent.
Android Resources
Android resources (res/) are not processed by default with the new plugin. You must explicitly enable them:
kotlin {
android {
androidResources { enable = true }
}
}Without this, files in src/androidMain/res/ will be ignored and R class generation will not happen.
Convention Plugin Refactoring
If you use convention plugins (build-logic), update them:
Before
// build-logic/convention/src/main/kotlin/KmpLibraryConventionPlugin.kt
class KmpLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("com.android.library")
pluginManager.apply("org.jetbrains.kotlin.multiplatform")
extensions.configure<LibraryExtension> {
compileSdk = 34
defaultConfig.minSdk = 24
}
}
}
}After
// build-logic/convention/src/main/kotlin/KmpLibraryConventionPlugin.kt
class KmpLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("org.jetbrains.kotlin.multiplatform")
pluginManager.apply("com.android.kotlin.multiplatform.library")
extensions.configure<KotlinMultiplatformExtension> {
android {
namespace = // set per-module or pass as parameter
compileSdk = 35
minSdk = 24
}
}
}
}
}The LibraryExtension class from AGP is no longer used. All Android configuration goes through KotlinMultiplatformExtension.android {}.
Quick Checklist
[ ] Update plugin IDs and versions (in
libs.versions.tomlif using version catalog, or directly in build files)[ ] Replace plugin alias in
build.gradle.kts[ ] Move
android {}block contents intokotlin { android {} }[ ] Replace
androidTarget {}withandroid {}[ ] Replace
kotlinOptionswithcompilerOptions[ ] Enable
androidResourcesif using Android resources[ ] Enable
withHostTest {}/withDeviceTest {}if using tests[ ] Add
withJava()if module contains Java source files[ ] Move consumer ProGuard rules to new DSL
[ ] Migrate top-level
dependenciesto source set dependencies[ ] Update convention plugins if applicable
[ ] Rename test source dirs:
androidUnitTesttoandroidHostTest,androidInstrumentedTesttoandroidDeviceTest[ ] Update root
build.gradle.ktsplugin declarations[ ] Run
./gradlew :module:assembleto verify
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
What our scanner noticed· Low risk
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- JetBrains
- Publisher
- JetBrains (Official)
- Distributed by
- JetBrains
- Source
- JetBrains/skills · kotlin-tooling-agp9-migration · commit 3f53782
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (written by AutoGineer)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by JetBrains or JetBrains.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download kotlin-tooling-agp9-migration.zip