Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

AGPBI D8 error from com.android.tools.r8.kotlin during an Android build

ErrorAGPBI: {"kind":"error","text":"com.android.tools.r8.kotlin.H","sources":[{}],"tool":"D8"}

Short answer

D8 and R8 read Kotlin metadata, and each Kotlin version needs a minimum Android Gradle Plugin. When Kotlin is newer than what your AGP bundles, the build fails inside com.android.tools.r8.kotlin. Compare your Kotlin and AGP versions with Google's table, then upgrade AGP or lower Kotlin.

  • Applies to AGP 8.x, Kotlin 2.x, Gradle 8.x/9, Android Studio current stable
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the Kotlin and Android Gradle Plugin versions the build actually resolves, then compare them with the table on Google's Kotlin support page.

    ./gradlew buildEnvironment | grep -E "kotlin-gradle-plugin|com.android.tools.build:gradle|com.android.tools:r8"
  2. 2Match what you see, then jump to its fix

    1. 1The failure started right after a Kotlin upgrade, or after adding a library built with a newer KotlinKotlin is newer than the D8 and R8 inside your AGPFix
    2. 2The build script or settings file adds com.android.tools:r8 to the buildscript classpathA D8 or R8 version was pinned older than the table allowsFix

What does the error look like?

  • AGPBI: {"kind":"error","text":"com.android.tools.r8.kotlin.H","sources":[{}],"tool":"D8"}

Cause 1 of 2

Kotlin is newer than the D8 and R8 inside your AGP

1Check

Google states that each Kotlin version from 1.4 on has a minimum AGP version, and that AGP bundles matching D8 and R8. For example, Kotlin 2.0 lists AGP 7.4.2 to 8.3, Kotlin 2.1 lists 7.4.2 to 8.7.2, and Kotlin 2.2 lists 7.3.1 to 8.10.

./gradlew buildEnvironment | grep -E "kotlin-gradle-plugin|com.android.tools.build:gradle"

2Fix

Upgrade the Android Gradle Plugin to a version the table lists for your Kotlin version, or lower Kotlin to the version your AGP supports. In Android Studio, the AGP Upgrade Assistant (Tools > AGP Upgrade Assistant) can do the AGP change.

// libs.versions.toml: raise the plugin to a version the table allows
[versions]
agp = "8.13.0"

3Verify

Sync and rebuild. The D8 step passes.

./gradlew clean assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 2

A D8 or R8 version was pinned older than the table allows

1Check

The table's R8 column matters only when you use D8 and R8 outside AGP or override the bundled version. A pinned older R8 then misses the minimum for your Kotlin.

grep -rn "com.android.tools:r8" settings.gradle* build.gradle* gradle/

2Fix

Remove the override so AGP's bundled version is used, or raise the pinned R8 to at least the version in the table for your Kotlin.

// delete this kind of line from the buildscript classpath:
// classpath("com.android.tools:r8:<old version>")

3Verify

Rebuild and confirm the resolved R8 version, which the first-step command prints.

./gradlew buildEnvironment | grep -E "com.android.tools:r8"

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Upgrade Kotlin and AGP together, checking Google's compatibility table first.
  • Avoid pinning com.android.tools:r8 unless you have a specific reason, and revisit the pin on every Kotlin upgrade.
  • Read library release notes for the Kotlin version they were built with before adding them.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.