All posts
Guide

Build fails after upgrading to AGP 9: how to fix it

What Android Gradle Plugin 9 breaks (built-in Kotlin, kapt, the new DSL, removed variant APIs), the exact errors, and what Flutter, React Native and Expo projects should do.

By the Renameproof team · · 7 min read

You bump the Android Gradle Plugin to 9.x, or your framework does it for you, and the build stops at configuration with an error like “Failed to apply plugin 'org.jetbrains.kotlin.android'” or “cannot be cast to class com.android.build.gradle.BaseExtension”. AGP 9.0 (January 2026) is a major release. It compiles Kotlin by itself, exposes only the new DSL interfaces, and removes the old variant API that many plugins still use.

What AGP 9 changes

  • Built-in Kotlin is on by default. AGP compiles Kotlin itself, so you no longer apply the kotlin-android plugin. AGP brings in the Kotlin Gradle plugin (KGP) at runtime, 2.2.10 or higher.
  • kapt is incompatible with built-in Kotlin. The org.jetbrains.kotlin.kapt plugin no longer works. Move to KSP, or use com.android.legacy-kapt at your AGP version as a stopgap.
  • Only the new DSL. The android block now implements only the public interfaces. Old types such as BaseExtension, and the old variant API (applicationVariants, libraryVariants, variantFilter), are gone. Use androidComponents.onVariants and beforeVariants instead.
  • New minimums. Gradle 9.1.0, SDK Build Tools 36.0.0 and JDK 17.
  • New defaults. targetSdk now defaults to compileSdk when it isn’t set (it used to default to minSdk). Each library must have a unique package name. Apps compile against a non-final R class. resValues and shader compilation are off by default.
  • Stricter R8. getDefaultProguardFile() accepts only proguard-android-optimize.txt. A keep file listed in the DSL that doesn’t exist now fails the build. Library consumer rules can’t contain global options like -dontoptimize.
  • Removed outright. Density split APKs, embedded Wear OS apps (wearApp), dexOptions, and the android.r8.integratedResourceShrinking property, which now throws an error if set.

Common errors after upgrading, and the fix

ErrorFix
Failed to apply plugin 'org.jetbrains.kotlin.android'. Cannot add extension with name 'kotlin', as there is an extension already registered with that name.Remove org.jetbrains.kotlin.android (or kotlin-android) from the module and top-level build files and from libs.versions.toml.
The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin support since AGP 9.0.Same fix. If the plugin is applied by a dependency you can’t change, set android.builtInKotlin=false and android.newDsl=false.
ClassCastException: … ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtensionA plugin or your build script uses the old DSL types. Update the plugin, or set android.newDsl=false while you wait.
applicationVariants (or libraryVariants) not found on the android extensionRewrite the logic with androidComponents { onVariants { … } }. Common cases are renaming APK outputs and setting BuildConfig fields per variant.
Minimum supported Gradle version is 9.1.0Update distributionUrl in gradle/wrapper/gradle-wrapper.properties to Gradle 9.1.0 or later.
kapt fails, or the kotlin-kapt plugin won’t applyMove Room, Hilt/Dagger, Moshi and similar processors to KSP. If one has no KSP support yet, apply com.android.legacy-kapt with your AGP version.
kotlinOptions is no longer recognized inside the android blockReplace android { kotlinOptions { … } } with a top-level kotlin { compilerOptions { … } } block. jvmTarget now defaults to compileOptions.targetCompatibility.
Release build fails on a missing ProGuard or keep fileFix the file name, or remove the line. Switch proguard-android.txt to proguard-android-optimize.txt.

How to upgrade a native Android project

  1. Run Tools → AGP Upgrade Assistant in Android Studio. It keeps old behavior where it can, so you can upgrade first and adopt new defaults later.
  2. Update the Gradle wrapper to 9.1.0 or later, and set Gradle’s JDK to 17 or later.
  3. Remove the kotlin-android plugin everywhere it is declared. If you need a KGP version other than the one AGP brings, declare it in the top-level buildscript classpath (2.2.10 or higher).
  4. Migrate kapt to KSP. Use com.android.legacy-kapt only for processors that don’t support KSP yet.
  5. Move kotlinOptions to kotlin.compilerOptions, and move Kotlin source directories from kotlin.sourceSets to android.sourceSets with the kotlin set.
  6. Replace the old variant API in your build logic with androidComponents, and update third-party Gradle plugins to versions that support AGP 9.
  7. Set targetSdk explicitly in every app and test module, so the new default doesn’t change it for you.
  8. Build a release bundle and run it. R8 now keeps less by default, so test the minified build, not just debug.

Flutter, React Native and Expo

Framework projects mostly get AGP 9 through a framework upgrade, not by editing the version themselves. The framework adds the two opt-out flags for you, so the app builds. What breaks is usually a plugin or native module that still applies kotlin-android or uses the old variant API.

FrameworkAGP 9 status (November 2026)What to do
FlutterFlutter 3.44 added AGP 9 support with built-in Kotlin off. The flutter tool adds android.newDsl=false and android.builtInKotlin=false to android/gradle.properties on the next build. Turning built-in Kotlin on needs Flutter 3.47 or later.In android/app/build.gradle(.kts), remove kotlin-android and replace kotlinOptions with kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_17 } }. Leave the flags in place until every plugin you use has migrated. If a plugin breaks the build, update it or ask its authors to migrate.
React NativeReact Native 0.87 and later ship AGP 9.2.1 and Gradle 9.4.1. The template’s gradle.properties sets android.builtInKotlin=false and android.newDsl=false, and app/build.gradle still applies org.jetbrains.kotlin.android.Upgrade with the React Native Upgrade Helper and keep both flags. Don’t remove kotlin-android until React Native drops the opt-outs. Update native libraries whose Gradle code uses applicationVariants or BaseExtension.
ExpoSDK 58 uses React Native 0.88. Its prebuild template sets the same two flags and Gradle 9.4.1.Run npx expo install --fix and rebuild. If prebuild output fails, look for config plugins or native modules that edit build.gradle with the old variant API, and update them.

Don’t delete the opt-out flags from a Flutter, React Native or Expo project just to silence the deprecation warning. Remove them only after the framework and every plugin you use support built-in Kotlin and the new DSL.

Questions people ask

What Gradle version does AGP 9 need?

Gradle 9.1.0 or later, SDK Build Tools 36.0.0 and JDK 17.

Does kapt still work with AGP 9?

The kotlin-kapt plugin doesn’t work with built-in Kotlin. Migrate to KSP, or use the com.android.legacy-kapt plugin at the same version as AGP until your processors support KSP.

How long can I keep android.newDsl=false and android.builtInKotlin=false?

Until AGP 10. Google says you won’t be able to opt out there, so treat the flags as temporary.

Why did my targetSdk change after upgrading?

If targetSdk isn’t set, AGP 9 now uses compileSdk instead of minSdk. Set it explicitly.

Should I upgrade AGP myself in a Flutter or React Native app?

Usually not. Upgrade the framework and let it pick the AGP, Gradle and Kotlin versions it was tested with.

Sources

  1. Android Developers: Android Gradle plugin 9.0 release notes
  2. Android Developers: Migrate to built-in Kotlin
  3. Android Developers: Migrate from kapt to KSP
  4. Flutter docs: Built-in Kotlin migration for app developers
  5. React Native community template (0.87) gradle.properties

Check your own name

Domains, both app stores, bundle IDs and every live site using the name, in under a minute.

Check a name

Keep reading

“App must support 16 KB memory page sizes”: how to fix it

Why Google Play flags your bundle for 16 KB page sizes, the February 1, 2027 cutoff, and how to fix it in Android Studio, Flutter, React Native, Expo and Unity.

November 27, 2026 · 6 min read

“Your app currently targets API level X”: how to fix it

Google Play now requires new apps and updates to target Android 16 (API level 36). Where to change targetSdk in Android Studio, Flutter, React Native, Expo and Unity.

November 27, 2026 · 5 min read
Build fails after upgrading to AGP 9: how to fix it · Renameproof