Android Studio Build Failed: JDK, Gradle or AGP Version Mismatch
Quick answer
Errors like 'Android Gradle plugin requires Java 17' or 'Unsupported class file major version' mean your JDK, Gradle and Android Gradle plugin versions do not match. Align them using the compatibility table.
Most likely fix: Set Gradle JDK to a matching version
How to fix it
Try these in order — the most common fix is first.
1. Set Gradle JDK to a matching version
- File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK
- Choose GRADLE_LOCAL_JAVA_HOME (default for new projects) or jbr-17
- AGP 8.x requires JDK 17; AGP 9.5 lists JDK 17 as minimum
Did this fix it?2. Make terminal and IDE agree
- Set JAVA_HOME to the same JDK the IDE uses
- Or set org.gradle.java.home in gradle.properties
Did this fix it?3. Match Gradle and AGP
- Check the compatibility table in the Android Gradle plugin release notes
- AGP 9.5 needs Gradle 9.6.0 as minimum and SDK Build Tools 36.0.0
- Use Tools > AGP Upgrade Assistant (or the upgrade prompt) to update safely
- Edit distributionUrl in gradle/wrapper/gradle-wrapper.properties if needed
Did this fix it?4. Align Kotlin
- Update the Kotlin Gradle plugin to a version that supports your AGP and Gradle
- If using Kotlin below 2.2, set kotlinOptions { jvmTarget = "17" } to match compileOptions
Did this fix it?5. Reset caches
- File > Invalidate Caches > Invalidate and Restart
- Run ./gradlew --stop and sync again
Did this fix it?
Symptoms
Build or sync fails with messages like 'Android Gradle plugin requires Java 17 to run. You are currently using Java 11', 'Unsupported class file major version', or a Kotlin or plugin version conflict after updating Studio.
Why it happens
- Gradle JDK older (or newer) than AGP supports
- Terminal builds use JAVA_HOME while the IDE uses a different JDK
- Gradle version below what the AGP requires
- Kotlin Gradle plugin version incompatible with AGP or Gradle
- Updating Android Studio without updating the project
This guide also covers
- android gradle plugin requires java 17
- unsupported class file major version android studio
- android studio kotlin version mismatch
- agp gradle compatibility
Still not working?
If Android Studio keeps failing, you're not alone. See every Android Studio problem users report or the alternatives people switch to.
Have an app idea? Our small team builds any software: web and mobile apps, games, desktop, AI tools. Price agreed together.
Talk to usOther Android Studio errors
- Android Studio Gradle Sync Failed
- Android Studio Emulator Not Starting
- Android Emulator HAXM / Hypervisor Error (VT-x, WHPX, AEHD)
- Android Studio Emulator Slow or Laggy
- Android Studio Device Offline or Not Detected (ADB)
- Android Studio Slow and Using Too Much RAM
- Android Studio Gradle Build Slow
- Android Studio SDK Location Not Found