Resolving "Could not resolve com.android.tools.build:gradle:8.0.1" Error
Problem Statement
You encounter this error when your Android project requires Java 17 compatibility but is configured to use Java 8 or Java 11. The core issue is a mismatch between Android Gradle Plugin (AGP) requirements and your project's Java configuration:
Could not resolve com.android.tools.build:gradle:8.0.1
...
Incompatible because this component declares an API of a component compatible with Java 11
and the consumer needed a runtime of a component compatible with Java 8
Key Causes
- AGP 8.0+ requires Java 17
- Your project is using an older Java version (8 or 11)
- Gradle JDK settings are misconfigured in Android Studio
- Gradle wrapper version is incompatible with AGP 8.0.1
Primary Solution: Update Gradle JDK to Java 17
In Android Studio
- Open Settings/Preferences (
File > Settings
on Windows/Linux,Android Studio > Preferences
on macOS) - Navigate to:
Build, Execution, Deployment > Build Tools > Gradle
- Under Gradle JDK, select JDK 17
- Click Apply and sync your project
TIP
If JDK 17 isn't listed, install it via File > Project Structure > SDKs > Add JDK
For Command Line/Gradle Wrapper
Set JAVA_HOME
to your JDK 17 installation:
Windows:
setx JAVA_HOME "C:\path\to\jdk-17" /M
Linux/macOS:
export JAVA_HOME=/path/to/jdk-17
Alternative Solutions
1. Update Gradle Wrapper Version
Edit gradle-wrapper.properties
to use Gradle 8.2+:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
Compatibility Note
- AGP 8.0.x requires Gradle 8.0-8.1
- AGP 8.2.x requires Gradle 8.2
2. Verify AGP Version
Ensure your AGP version matches the Gradle version:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:8.2.0'
}
}
3. Clean Gradle Cache (Optional)
If issues persist, clean the Gradle cache:
# Windows:
rmdir /s /q %USERPROFILE%\.gradle\caches
# Linux/macOS:
rm -rf ~/.gradle/caches
Additional Checks
For Kotlin Projects
Ensure Java toolchain compatibility:
kotlin {
jvmToolchain(17)
}
Common Pitfall
Avoid downgrading Java compatibility settings like this in AGP 8+ projects:
compileOptions {
sourceCompatibility JavaVersion.VERSION_17 // Required for AGP 8+
targetCompatibility JavaVersion.VERSION_17
}
Conclusion
This error occurs because AGP 8.0+ requires Java 17 support at both the Gradle runtime and project configuration levels. The most reliable solution is:
- Update Gradle JDK to Java 17
- Use compatible Gradle wrapper distribution (8.x)
- Verify AGP version matches Gradle requirements
For Android Studio users, the JDK setting is the key resolution. Command-line users should set JAVA_HOME
to JDK 17 before running Gradle commands.
Future-Proofing
- Always check AGP/Gradle compatibility at Android Gradle Plugin Compatibility
- New AGP versions may require newer JDKs