Skip to content

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

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:

kotlin
// 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
// 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:

groovy
// 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:

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:

groovy
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):

groovy
// 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:

groovy
ext {
    kotlin_version = '1.8.10' // Or latest stable
}

Key Recommendations

  1. Try solutions in this order:

    1. Add explicit R8 dependency (Solution 1)
    2. Upgrade AGP/Gradle/Kotlin (Solution 2)
    3. Increase minSdk (Solution 3)
  2. After applying fixes:

    • Run ./gradlew clean
    • Invalidate Android Studio caches (File > Invalidate Caches)
    • Update third-party libraries to prevent version conflicts
  3. Verify compatibility:

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.