Generated banner for Kotlin Tooling Agp9 Migration
Generated logo for Kotlin Tooling Agp9 Migration

Kotlin Tooling Agp9 Migration

JetBrainsOfficialCreated by JetBrainsDistributed by JetBrains

  • Skill
  • Workflow
  • Software development
  • Apache-2.0
  • Low risk
  • Has scripts

From the author

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.
— the description by JetBrains

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

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/jetbrains/kotlin-tooling-agp9-migration/download
  2. Unzip 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:

  1. Read settings.gradle.kts (or .gradle) to find all modules

  2. For each module, read its build.gradle.kts to identify which plugins are applied

  3. Check 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 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"

  4. Read gradle/wrapper/gradle-wrapper.properties for the Gradle version

  5. Check gradle.properties for any existing workarounds (android.enableLegacyVariantApi)

  6. Check for org.jetbrains.kotlin.android plugin usage — AGP 9.0 has built-in Kotlin and this plugin must be removed

  7. Check for org.jetbrains.kotlin.kapt plugin usage — incompatible with built-in Kotlin, must migrate to KSP or com.android.legacy-kapt

  8. Check 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 pluginsMigration path
kotlin.multiplatform + com.android.libraryPath A — Library plugin swap
kotlin.multiplatform + com.android.applicationPath B — Mandatory Android split
kotlin.multiplatform with multiple platform entry points in one modulePath 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:

  1. Replace plugin: com.android.library → com.android.kotlin.multiplatform.library

  2. Remove org.jetbrains.kotlin.android plugin if present (AGP 9.0 has built-in Kotlin support)

  3. Migrate DSL: Move config from top-level android {} block into kotlin { android {} }:

    kotlin {
        android {
            namespace = "com.example.lib"
            compileSdk = 35
            minSdk = 24
        }
    }
  4. Rename source directories (only if the module uses classic Android layout instead of KMP layout):

    • src/main → src/androidMain

    • src/test → src/androidHostTest

    • src/androidTest → src/androidDeviceTest

    • If the module already uses src/androidMain/, no directory renames are needed

  5. Move dependencies from top-level dependencies {} into sourceSets:

    kotlin {
        sourceSets {
            androidMain.dependencies {
                implementation("androidx.appcompat:appcompat:1.7.0")
            }
        }
    }
  6. Enable resources explicitly if the module uses Android resources:

    kotlin {
        android {
            androidResources { enable = true }
        }
    }
  7. Enable Java compilation if module has .java source files:

    kotlin {
        android {
            withJava()
        }
    }
  8. Enable tests explicitly if the module has unit or instrumented tests:

    kotlin {
        android {
            withHostTest { isIncludeAndroidResources = true }
            withDeviceTest {
                instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
            }
        }
    }
  9. Update Compose tooling dependency:

    // Old: debugImplementation(libs.androidx.compose.ui.tooling)
    // New:
    dependencies {
        androidRuntimeClasspath(libs.androidx.compose.ui.tooling)
    }
  10. 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:

  1. Create androidApp module with its own build.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)
    }
  2. Move Android entry point code from 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 location

    • Android Application class if present

    • App-level resources (launcher icons, theme, etc.)

  3. Add to settings.gradle.kts: include(":androidApp")

  4. Add to root build.gradle.kts: plugin declarations with apply false

  5. Convert original module from application to library using Path A steps

  6. Ensure different namespaces: app module and library module must have distinct namespaces

  7. Remove from shared module: applicationId, targetSdk, versionCode, versionName

  8. Update IDE run configurations: change the module from the old module to androidApp

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
  1. Apply Path B first — extract androidApp (mandatory for AGP 9.0)

  2. Extract desktopApp (if desktop target exists):

    • Create module with org.jetbrains.compose and application {} plugin

    • Move main() function from desktopMain to desktopApp/src/main/kotlin/

    • Move compose.desktop { application { ... } } config to desktopApp/build.gradle.kts

    • Add dependency on shared module

  3. Extract webApp (if wasmJs/js target exists):

    • Create module with appropriate Kotlin/JS or Kotlin/Wasm configuration

    • Move web entry point from wasmJsMain/jsMain to webApp/src/wasmJsMain/kotlin/

    • Move browser/distribution config to webApp/build.gradle.kts

    • Add dependency on shared module

  4. iOS — typically already in a separate iosApp directory. Verify:

    • Framework export config (binaries.framework) stays in shared module

    • Xcode project references the correct framework path

  5. Rename module from composeApp to shared:

    • Rename directory

    • Update settings.gradle.kts include

    • Update all dependency references across modules

  6. 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 platforms

  • sharedUI — Compose Multiplatform UI consumed only by platforms using shared UI

Variant: Server

If the project includes a server target:

  • Add server module at the root

  • Move all client modules under an app/ directory

  • Add core module for code shared between server and client (models, validation)

Version Updates

These are required regardless of migration path:

  1. Gradle wrapper — update to 9.1.0+:

    # gradle/wrapper/gradle-wrapper.properties
    distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
  2. AGP 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
    }
  3. 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")
    }
  4. Root build.gradle.kts — add apply false for new plugin (see examples above)

  5. JDK — ensure JDK 17+ is used (required by AGP 9.0)

  6. SDK Build Tools — update to 36.0.0:

    Install via SDK Manager or configure in android { buildToolsVersion = "36.0.0" }
  7. 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)

  8. 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:

  1. Disable globally: android.builtInKotlin=false in gradle.properties

  2. Enable per migrated module by applying the opt-in plugin:

    plugins {
        id("com.android.built-in-kotlin") version "AGP_VERSION"
    }
  3. Follow Steps 1-4 for that module

  4. Once all modules are migrated, remove android.builtInKotlin=false and all com.android.built-in-kotlin plugins

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-out

Warning: 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:

PropertyOld DefaultNew DefaultAction
android.uniquePackageNamesfalsetrueEnsure each library has a unique namespace
android.enableAppCompileTimeRClassfalsetrueRefactor switch on R fields to if/else
android.defaults.buildfeatures.resvaluestruefalseEnable resValues = true where needed
android.defaults.buildfeatures.shaderstruefalseEnable shaders where needed
android.r8.optimizedResourceShrinkingfalsetrueReview R8 keep rules
android.r8.strictFullModeForKeepRulesfalsetrueUpdate keep rules to be explicit
android.proguard.failOnMissingFilesfalsetrueRemove invalid ProGuard file references
android.r8.proguardAndroidTxt.disallowedfalsetrueUse proguard-android-optimize.txt only
android.r8.globalOptionsInConsumerRules.disallowedfalsetrueRemove global options from library consumer rules
android.sourceset.disallowProviderfalsetrueUse Sources API on androidComponents
android.sdk.defaultTargetSdkToCompileSdkIfUnsetfalsetrueSpecify targetSdk explicitly
android.onlyEnableUnitTestForTheTestedBuildTypefalsetrueOnly if testing non-default build types

Check for and remove properties that now cause errors:

  • android.r8.integratedResourceShrinking — removed, always on

  • android.enableNewResourceShrinker.preciseShrinking — removed, always on

Pure Android Tips

For non-KMP Android modules upgrading to AGP 9.0:

  • Remove org.jetbrains.kotlin.android plugin — AGP 9.0 includes Kotlin support built-in (see "Built-in Kotlin Migration" above)

  • Migrate kapt to KSP or com.android.legacy-kapt

  • Migrate kotlinOptions to kotlin { compilerOptions {} }

  • Migrate kotlin.sourceSets to android.sourceSets with .kotlin accessor

  • Review new DSL interfaces — BaseExtension is removed; use CommonExtension or specific extension types

  • Java default changed from Java 8 to Java 11 — ensure compileOptions reflects this

  • R class is now compile-time non-final in app modules — refactor any switch statements on R class fields to if/else

  • targetSdk defaults to compileSdk if not set — specify targetSdk explicitly to avoid surprises

  • NDK default changed to r28c — specify ndkVersion explicitly if using native code

  • Temporary opt-out: android.builtInKotlin=false + android.newDsl=false in gradle.properties (removed in AGP 10)

Verification

After migration, verify with the checklist. Key checks:

  1. ./gradlew build succeeds with no errors

  2. ./gradlew :androidApp:assembleDebug succeeds (if app module exists)

  3. No com.android.library or com.android.application in KMP modules

  4. No org.jetbrains.kotlin.android in AGP 9.0 modules

  5. Source sets use correct names (androidMain, androidHostTest, androidDeviceTest)

  6. No deprecation warnings about variant API

  7. 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/AppConfiguration interface, or use BuildKonfig or gradle-buildconfig-plugin for compile-time constants

  • No 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.library module

  • Compose resources crash without androidResources { enable = true } (CMP-9547)

  • Consumer ProGuard rules silently dropped if not migrated to consumerProguardFiles.add(file(...)) in new DSL

  • KSP requires version 2.3.4+ for AGP 9.0 compatibility

AGP 9.0 General Issues
  • Built-in Kotlin conflicts — org.jetbrains.kotlin.android must be removed; kapt must be replaced

  • BaseExtension removed — convention plugins using old DSL types need rewriting

  • Variant APIs removed — applicationVariants, libraryVariants, variantFilter replaced by androidComponents

  • R class non-final — switch on R fields fails in app modules; refactor to if/else

  • targetSdk 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

Files

references/KNOWN-ISSUES.md

Known Issues: KMP AGP 9.0 Library Migration

Comprehensive list of gotchas, limitations, and workarounds when migrating to com.android.kotlin.multiplatform.library. Based on official Android documentation and community experience.


1. BuildConfig Removed in Libraries

Problem: The BuildConfig class is not generated for KMP library modules. Code referencing BuildConfig.DEBUG, BuildConfig.VERSION_NAME, or custom buildConfigField entries will fail to compile.

Impact: High. Many libraries use BuildConfig.DEBUG for logging gates and buildConfigField for compile-time constants.

Workaround -- AppConfiguration DI Pattern:

// In commonMain
expect class AppConfiguration {
    val isDebug: Boolean
    val versionName: String
    val apiBaseUrl: String
}

// In androidMain
actual class AppConfiguration(private val context: Context) {
    actual val isDebug: Boolean = (context.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) != 0
    actual val versionName: String = context.packageManager
        .getPackageInfo(context.packageName, 0).versionName ?: "unknown"
    actual val apiBaseUrl: String = if (isDebug) "https://dev.api.example.com" else "https://api.example.com"
}

// In iosMain
actual class AppConfiguration {
    actual val isDebug: Boolean = Platform.isDebugBinary
    actual val versionName: String = NSBundle.mainBundle.objectForInfoDictionaryKey("CFBundleShortVersionString") as? String ?: "unknown"
    actual val apiBaseUrl: String = if (isDebug) "https://dev.api.example.com" else "https://api.example.com"
}

Inject AppConfiguration via your DI framework (Koin, kotlin-inject, manual DI).

Alternative A — BuildKonfig plugin (github.com/yshrsmz/BuildKonfig):

Generates expect/actual BuildConfig objects across all KMP targets. Supports typed fields (String, Int, Long, Float, Boolean), target-specific overrides, and a flavor system via Gradle properties.

// build.gradle.kts
plugins {
    id("com.codingfeline.buildkonfig")
}

buildkonfig {
    packageName = "com.example.shared"

    defaultConfigs {
        buildConfigField(STRING, "API_BASE_URL", "https://api.example.com")
        buildConfigField(BOOLEAN, "IS_DEBUG", "false")
        buildConfigField(STRING, "VERSION_NAME", "1.0.0")
    }

    // Optional: target-specific overrides
    targetConfigs {
        create("android") {
            buildConfigField(STRING, "PLATFORM", "android")
        }
        create("ios") {
            buildConfigField(STRING, "PLATFORM", "ios")
        }
    }
}

Use flavors for debug/release by setting buildkonfig.flavor=dev in gradle.properties or passing -Pbuildkonfig.flavor=release on CLI:

defaultConfigs("dev") {
    buildConfigField(STRING, "API_BASE_URL", "https://dev.api.example.com")
    buildConfigField(BOOLEAN, "IS_DEBUG", "true")
}
defaultConfigs("release") {
    buildConfigField(STRING, "API_BASE_URL", "https://api.example.com")
    buildConfigField(BOOLEAN, "IS_DEBUG", "false")
}

Alternative B — gradle-buildconfig-plugin (github.com/gmazzo/gradle-buildconfig-plugin):

More general-purpose; supports Java, Kotlin, Groovy, and KMP. Richer type support (arrays, maps, Files, URIs). Uses expect/actual for KMP via explicit expect() calls.

// build.gradle.kts
plugins {
    id("com.github.gmazzo.buildconfig")
}

buildConfig {
    packageName("com.example.shared")

    buildConfigField("APP_NAME", project.name)
    buildConfigField("VERSION", "1.0.0")
    buildConfigField("IS_DEBUG", false)

    // Platform-specific fields using expect/actual
    buildConfigField("PLATFORM", expect<String>())
}

// In source set configurations:
sourceSets.named("androidMain") {
    buildConfigField("PLATFORM", "android")
}
sourceSets.named("iosMain") {
    buildConfigField("PLATFORM", "ios")
}

Important limitation: Neither plugin replaces Android build variants fully. They provide compile-time constants only. Build type-specific dependencies, resources, source sets, signing configs, and minification settings must be handled in the application module (which still supports variants) or via runtime configuration.


2. NDK / JNI Unsupported

Problem: The KMP library plugin does not support externalNativeBuild, ndkVersion, or JNI source compilation. Modules that use C/C++ native code via NDK cannot be migrated directly.

Impact: Medium. Affects modules with native image processing, crypto, or media libraries.

Workaround -- Proxy Interface Pattern:

Keep the JNI module as a classic com.android.library module and have the KMP module depend on it:

jni-bridge/                 # com.android.library (AGP 8.x compatible in AGP 9.0)
  build.gradle.kts
  src/main/jni/             # C/C++ sources
  src/main/kotlin/          # JNI bindings

shared/                     # com.android.kotlin.multiplatform.library
  build.gradle.kts
// shared/build.gradle.kts
kotlin {
    sourceSets {
        androidMain.dependencies {
            implementation(project(":jni-bridge"))
        }
    }
}

Define an interface in commonMain and implement it in androidMain by delegating to the JNI bridge.


3. No Build Variants

Problem: The KMP library plugin produces a single build variant. There are no debug/release build types and no product flavors. Code that depends on variant-specific behavior, resources, or dependencies must be restructured.

Impact: High. Affects projects using flavor-specific dependencies, resources, or source sets.

Workaround -- Single Variant Architecture:

  • Move all variant-dependent logic to the application module (which still supports variants).

  • Use runtime configuration instead of compile-time variants.

  • Use expect/actual with different actual implementations selected by DI based on runtime config.

  • For library-specific debug/release behavior, use the AppConfiguration pattern from issue 1.

  • For compile-time constants that vary by build flavor, use BuildKonfig or gradle-buildconfig-plugin (see issue 1 alternatives). These provide a flavor-like system for KMP but do NOT replace variant-specific dependencies, resources, signing, or minification.


4. Compose Resources Require Explicit Enable

Problem: Android resources (res/ directory) are not processed by default with the KMP library plugin. If you forget to enable them, resource references (R.string.*, R.drawable.*) will fail to resolve. This is tracked as CMP-9547.

Impact: High. Silent failure -- resources are simply ignored without an error until you try to reference them.

Fix:

kotlin {
    android {
        androidResources { enable = true }
    }
}

Note: This is separate from Compose Multiplatform resources (composeResources/), which are handled by the compose resources plugin and do not need this flag.


5. Consumer ProGuard Rules Silently Dropped

Problem: If you had consumerProguardFiles in the old android { defaultConfig {} } block and did not migrate it to the new DSL location, the rules are silently ignored. No warning is emitted.

Impact: Medium. Can cause runtime crashes in release builds of consuming applications.

Fix:

// Old (silently ignored)
android {
    defaultConfig {
        consumerProguardFiles("consumer-rules.pro")
    }
}

// New
kotlin {
    android {
        consumerProguardFiles.add(file("consumer-rules.pro"))
    }
}

6. Convention Plugin Refactoring Needed

Problem: Build-logic convention plugins that apply com.android.library and configure the LibraryExtension must be rewritten to use the KMP library plugin and KotlinMultiplatformExtension.

Impact: Medium to High for projects with extensive build-logic modules.

Key Changes:

// Old
import com.android.build.gradle.LibraryExtension

class MyConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        target.pluginManager.apply("com.android.library")
        target.extensions.configure<LibraryExtension> {
            compileSdk = 34
            defaultConfig.minSdk = 24
        }
    }
}

// New
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class MyConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        target.pluginManager.apply("org.jetbrains.kotlin.multiplatform")
        target.pluginManager.apply("com.android.kotlin.multiplatform.library")
        target.extensions.configure<KotlinMultiplatformExtension> {
            android {
                compileSdk = 35
                minSdk = 24
            }
        }
    }
}

7. androidUnitTest to androidHostTest Rename

Problem: The source set androidUnitTest is renamed to androidHostTest. The source set androidInstrumentedTest is renamed to androidDeviceTest. The old names still work as aliases but are deprecated.

Impact: Low. Aliases provide backward compatibility, but you should rename for clarity.

Action Items:

  • Rename src/androidUnitTest/ to src/androidHostTest/

  • Rename src/androidInstrumentedTest/ to src/androidDeviceTest/

  • Update sourceSets references in build.gradle.kts

  • Update CI scripts that reference the old directory names


8. Lint useK2Uast Deprecated

Problem: The lint { useK2Uast = true } option is deprecated. With KGP 2.0+ and AGP 9.0, K2 UAST is the default and only implementation.

Impact: Low. Build warning only.

Fix: Remove the line:

// Remove this
lint {
    useK2Uast = true  // DELETE
}

9. Packaging Exclusions Syntax Change

Problem: The packaging exclusions DSL has a subtle syntax difference. The old brace-expansion syntax may not work correctly.

Impact: Low. Build may fail or produce unexpected results.

Fix:

// Old (may not work correctly in AGP 9.0)
packaging {
    resources {
        excludes += "/META-INF/{AL2.0,LGPL2.1}"
    }
}

// New (explicit entries)
packaging {
    resources {
        excludes.add("/META-INF/AL2.0")
        excludes.add("/META-INF/LGPL2.1")
    }
}

10. Static BuildConfig.DEBUG for Tree-Shaking No Longer Available

Problem: In classic Android libraries, BuildConfig.DEBUG was a static final boolean that the compiler could use for dead-code elimination (tree-shaking). Without BuildConfig in KMP libraries, this optimization path is lost.

Impact: Low to Medium. Debug-only code paths may be included in release builds.

Workaround:

Use R8 rules in the application module to remove debug code:

# In the app module's proguard-rules.pro
-assumenosideeffects class com.example.shared.AppConfiguration {
    boolean isDebug() return false;
}

Or use compile-time constants from the application module passed via DI.


11. android.builtInKotlin=false (Temporary Opt-Out)

Problem: AGP 9.0 bundles Kotlin compilation for com.android.application modules, meaning you should NOT apply the kotlin-android plugin separately. If you have tooling or plugins that conflict with the built-in Kotlin support, you can temporarily disable it.

Temporary Workaround:

# gradle.properties
android.builtInKotlin=false

Warning: This flag is temporary and will be removed in a future AGP version. Use it only to unblock migration while you fix plugin conflicts.

When you need this:

  • You have custom Kotlin compiler plugin configurations that conflict with AGP's built-in setup

  • A third-party Gradle plugin explicitly applies kotlin-android and conflicts


12. IDE Support Matrix

IDEKMP Library Plugin SupportNotes
Android Studio Otter 3 (2025.2.3)FullFirst version with full AGP 9.0 support
Android Studio Narwhal (2025.1)PartialCan build but limited code insight for new DSL
Android Studio Meerkat (2024.3)NoneDoes not recognize the KMP library plugin
IntelliJ IDEANot supportedDoes not support AGP 9.0 as of 2025.3, use Android Studio
  • Use Android Studio Otter 3 or later. This is currently the only IDE with full AGP 9.0 + KMP library plugin support.

  • IntelliJ IDEA does not support AGP 9.0 — even with the Android plugin installed, project sync and build integration will not work correctly. If the project uses IntelliJ IDEA, recommend switching to Android Studio for Android/KMP development.

  • Ensure the Kotlin plugin in your IDE matches the KGP version in your project.


13. kapt Incompatible with Built-in Kotlin

Problem: The org.jetbrains.kotlin.kapt plugin is incompatible with AGP 9.0's built-in Kotlin support. Applying both causes a build failure.

Impact: High. Many projects still use kapt for annotation processing

Workaround:

Preferred: Migrate to KSP (Kotlin Symbol Processing). Most annotation processors now support KSP.

Fallback: Replace with com.android.legacy-kapt (versioned with AGP):

# gradle/libs.versions.toml
[plugins]
legacy-kapt = { id = "com.android.legacy-kapt", version.ref = "agp" }
// Module build.gradle.kts
plugins {
    // REMOVE: alias(libs.plugins.kotlin.kapt)
    alias(libs.plugins.legacy.kapt)
}

14. New DSL Interfaces (BaseExtension Removed)

Problem: AGP 9.0 exclusively uses new public DSL interfaces. The old BaseExtension, AppExtension, LibraryExtension types from com.android.build.gradle are removed. Build logic or convention plugins casting to these types will fail with ClassCastException.

Impact: High for projects with custom build logic or convention plugins.

Error message:

java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated
    cannot be cast to class com.android.build.gradle.BaseExtension

Fix:

// Old
import com.android.build.gradle.BaseExtension
val ext = extensions.getByType(BaseExtension::class)

// New
import com.android.build.api.dsl.CommonExtension
val ext = extensions.getByType(CommonExtension::class)

Temporary opt-out: android.newDsl=false in gradle.properties (removed in AGP 10.0).


15. Deprecated Variant APIs Removed

Problem: The following APIs are removed in AGP 9.0: applicationVariants, libraryVariants, testVariants, unitTestVariants, variantFilter. Build scripts or plugins using these will fail.

Impact: Medium-High. Affects custom build logic and many third-party plugins.

Fix:

// Old
android {
    applicationVariants.all { variant ->
        variant.signingConfig.enableV1Signing = false
    }
}

// New
androidComponents {
    onVariants { variant ->
        variant.signingConfig.enableV1Signing.set(false)
    }
}

Replace variantFilter with androidComponents.beforeVariants().


16. R8 and ProGuard Rule Changes

Problem: AGP 9.0 changes several R8 defaults:

  • android.r8.strictFullModeForKeepRules=true — keep rules no longer implicitly keep default constructors

  • android.r8.proguardAndroidTxt.disallowed=true — only proguard-android-optimize.txt is supported

  • android.r8.globalOptionsInConsumerRules.disallowed=true — library consumer rules cannot contain global options (like -dontobfuscate)

  • Keep rules no longer propagate to synthesized companion methods

Impact: Medium. Release builds may crash or behave differently without rule updates.

Fix:

  • Review all ProGuard/R8 keep rules; add explicit rules for default constructors if needed

  • Switch to proguard-android-optimize.txt in getDefaultProguardFile()

  • Remove global options (-dontobfuscate, -dontoptimize) from library consumer rules

  • New option: -processkotlinnullchecks keep|remove_message|remove to control Kotlin null checks


17. Removed Features

Problem: Several features are removed in AGP 9.0 with no replacement:

  • Embedded Wear OS app support — wearApp configurations removed

  • Density split APK — use app bundles instead

  • androidDependencies and sourceSets report tasks — removed

  • dexOptions DSL — removed (d8 handles this automatically)

  • RenderScript — disabled by default, enable per-module if needed: buildFeatures { renderScript = true }

  • AIDL — disabled by default, enable per-module if needed: buildFeatures { aidl = true }

Impact: Low-Medium. Only affects projects using these specific features.


18. R Class Non-Final in Application Modules

Problem: AGP 9.0 makes R class fields compile-time non-final in application modules (android.enableAppCompileTimeRClass=true is now default). Code using switch statements on R class fields (like R.id.some_view) will fail to compile because switch requires compile-time constants.

Impact: Medium. Common in older Java codebases using switch(view.getId()).

Fix: Refactor switch statements to if/else:

// Old (fails with AGP 9.0)
switch (view.getId()) {
    case R.id.button1: // ...
    case R.id.button2: // ...
}

// New
int id = view.getId();
if (id == R.id.button1) { /* ... */ }
else if (id == R.id.button2) { /* ... */ }

19. targetSdk Defaults to compileSdk

Problem: AGP 9.0 changes targetSdk to default to compileSdk when not explicitly set (previously defaulted to minSdk). This can silently change app behavior if targetSdk was intentionally unset.

Impact: Medium. May trigger new runtime behavior changes associated with higher API levels.

Fix: Explicitly set targetSdk in all application modules:

android {
    defaultConfig {
        targetSdk = 35  // Set explicitly
    }
}

20. Third-Party Plugin Compatibility

Problem: Many third-party Gradle plugins are incompatible with AGP 9.0 due to removed variant APIs, new DSL interfaces, or built-in Kotlin conflicts. See the main SKILL.md "Plugin Compatibility" section for the full compatibility table.

Impact: High. Can completely block migration.

Key plugins requiring opt-out flags:

  • detekt < 2.0.0, ktlint, SQLDelight, Paparazzi, protobuf — see SKILL.md for specific flags


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