AGPBI D8 Error: com.android.tools.r8.kotlin.H
Problem Statement
Android developers encounter the AGPBI: {"kind":"error","text":"com.android.tools.r8.kotlin.H"}
error when building projects, particularly after updating to Android Studio Hedgehog | 2023.1.1 | Patch 2. This issue manifests with the Kotlin compiler (D8) and includes a misleading circular dependency message (Caused by: [CIRCULAR REFERENCE: com.android.tools.r8.kotlin.H]
), even when no actual circular dependencies exist in the project.
Key characteristics:
- Occurs during builds after updating Android Studio, Kotlin (1.7.0+), or Gradle (7.4+)
- Typically appears with AGP versions 7.4.x
- Affects both debug and release builds
- Error message provides minimal actionable information
Recommended Solutions
1. Specify R8 Version in Build Script (Preferred)
Add the R8 dependency directly in your project-level build.gradle.kts
(or build.gradle
) to override the default version:
// Top-level build.gradle.kts
buildscript {
repositories {
maven { url = uri("https://storage.googleapis.com/r8-releases/raw") }
}
dependencies {
classpath("com.android.tools:r8:8.3.37") // Use latest stable version
}
}
// Groovy alternative (build.gradle)
buildscript {
repositories {
maven { url 'https://storage.googleapis.com/r8-releases/raw' }
}
dependencies {
classpath 'com.android.tools:r8:8.3.37'
}
}
Explanation:
This resolves compatibility issues by explicitly defining a compatible R8 version. Works with:
- Gradle 7.5.1
- AGP 7.4.0+
- Kotlin 1.8.20+
- minSdk 21+ (no changes required)
After adding this, clean your project (./gradlew clean
) and rebuild.
2. Update Android Gradle Plugin and Kotlin
Use compatible versions in your project configuration:
// Top-level build.gradle
plugins {
id 'com.android.application' version '8.2.2' apply false
id 'com.android.library' version '8.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.9.20' apply false
}
ext {
kotlin_version = '1.9.20'
}
Update gradle-wrapper.properties
:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
Explanation:
Keeping AGP and Kotlin versions synchronized prevents compatibility conflicts. AGP 8.x requires Gradle 8.x via wrapper.
3. Increase minSdk Version (Fallback)
Modify your app's build.gradle
:
android {
defaultConfig {
minSdk 24 // Minimum 24 recommended
targetSdk 34
}
}
WARNING
This solution has tradeoffs:
- 🛑 Breaks compatibility with devices below Android 7.0
- Use only if supporting older devices isn't required
- Prefer R8 solution instead when possible
4. Temporary Workarounds (If Other Solutions Fail)
Downgrade AGP (Short-term Fix):
// Top-level build.gradle
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
}
Adjust Kotlin Version:
ext {
kotlin_version = '1.8.10' // Or latest stable
}
Key Recommendations
Try solutions in this order:
- Add explicit R8 dependency (Solution 1)
- Upgrade AGP/Gradle/Kotlin (Solution 2)
- Increase minSdk (Solution 3)
After applying fixes:
- Run
./gradlew clean
- Invalidate Android Studio caches (File > Invalidate Caches)
- Update third-party libraries to prevent version conflicts
- Run
Verify compatibility:
- Check Android Gradle Plugin release notes for known issues
- Ensure Kotlin compatibility with AGP versions
- Confirm Android Gradle Plugin matches Gradle wrapper version
TIP
The AGPBI error stems from R8/Kotlin compatibility problems in build tools, not actual circular dependencies. Prioritize updating R8 or build tools before modifying SDK targets.
If issues persist, check for updates to these solutions as newer AGP/R8 versions continue addressing this error.