AGPBI D8 error from com.android.tools.r8.kotlin during an Android build
AGPBI: {"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.
Fix it fast
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"2Match what you see, then jump to its fix
- 1
The 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
The 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
- 1
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 assembleDebugConfirmed by developer.android.com
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
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:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Nuclear Home VideoA video-streaming Android app built from scratch, engineered for smooth playback.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Android build fails because a product flavor has no flavor dimension
The flavor 'flavor_name' is not assigned to a flavor dimension.
Android Gradle plugin refuses to build when a product flavor is not assigned to a flavor dimension.
2 causes, each with a fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
Android build fails because two libraries ship the same META-INF file
More than one file was found with OS independent path
Two dependencies put a file at the same path inside the APK and the plugin will not guess which one wins.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fix