Fix "Android Gradle plugin requires Java 17 to run"
Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
- Failed to apply plugin 'com.android.internal.application'. > Android Gradle plugin requires Java 17 to run. You are currently using Java 11. Your current JDK is located in /usr/lib/jvm/java-11-openjdk-amd64
- Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
- Dependency requires at least JVM runtime version 17. This build uses a Java 11 JVM.
- You can try some of the following options: - changing the IDE settings. - changing the JAVA_HOME environment variable. - changing `org.gradle.java.home` in `gradle.properties`.
Gradle runs with a JDK that is too old (often Java 11 or 8) while Android Gradle plugin 8 or later requires Java 17. Select a JDK 17 or newer as the Gradle JDK in Android Studio, or point JAVA_HOME to it on the command line (and flutter config --jdk-dir for Flutter).
What this error means
The Android Gradle plugin (AGP, com.android.application) is itself Java code running inside the Gradle process. Since AGP 8.0, it is compiled for Java 17 and checks at startup the version of the JVM running Gradle. That JVM is not necessarily your project’s: it is the "Gradle JDK" selected in Android Studio, or in a terminal the one from JAVA_HOME (otherwise the java on the PATH), or org.gradle.java.home if set. The message gives the version found and its location: you just need to give Gradle a recent enough JDK.
Common causes
JAVA_HOMEpoints to an old JDK: the build works in Android Studio but fails with./gradlew,flutter runornpx react-native run-android.- Wrong Gradle JDK in Android Studio: the project uses a separately installed JDK 11 instead of the JetBrains Runtime bundled with the IDE.
- Plugin upgrade: moving to AGP 8 (or a recent Flutter/React Native template) without changing JDK.
- Hard-coded
org.gradle.java.homeingradle.propertiespointing to an old JDK, or a CI image with Java 11.
Step-by-step fix
-
See which Java Gradle uses
Compare the
javaversion, theJAVA_HOMEvalue and the JVM reported by Gradle. On Windows, usegradlew.bat -versionandecho $env:JAVA_HOMEin PowerShell.java -version echo $JAVA_HOME cd android && ./gradlew -version -
Android Studio: pick the right Gradle JDK
Open Settings (Preferences on macOS) > Build, Execution, Deployment > Build Tools > Gradle, then set Gradle JDK to the bundled JetBrains Runtime (
jbr-17orjbr-21) or a JDK 17+. Then click Sync Project with Gradle Files. -
macOS / Linux terminal: point JAVA_HOME to a JDK 17
Use the JDK bundled with Android Studio or install one (Temurin, OpenJDK). Add the
exportline to your~/.zshrcor~/.bashrcto make it permanent.# macOS: JDK bundled with Android Studio export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home" # macOS: or an installed JDK 17 export JAVA_HOME=$(/usr/libexec/java_home -v 17) # Linux (Debian/Ubuntu) sudo apt install openjdk-17-jdk export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 java -version -
Windows terminal: set JAVA_HOME
In PowerShell,
setxsaves the variable for future terminals; close and reopen your terminal (and your editor) afterwards.setx JAVA_HOME "C:\Program Files\Android\Android Studio\jbr" # in a new terminal: & "$env:JAVA_HOME\bin\java" -version -
Flutter: tell it which JDK to use
Flutter can use a specific JDK regardless of
JAVA_HOME. Then check the "Java binary at" line offlutter doctor -v.flutter config --jdk-dir="/Applications/Android Studio.app/Contents/jbr/Contents/Home" flutter doctor -v -
Stop old Gradle daemons and rebuild
A Gradle daemon started with the old JDK can stay alive. Stop them, then build again. If
org.gradle.java.homeis set ingradle.properties, fix or remove that line.cd android ./gradlew --stop ./gradlew assembleDebug
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Use the same JDK everywhere: Android Studio’s JetBrains Runtime, referenced by
JAVA_HOMEin your terminal. - Do not put a machine-specific
org.gradle.java.homepath in the committedgradle.properties: put it in~/.gradle/gradle.propertiesif needed. - In CI, pin the Java version, for example with
actions/setup-java(distribution: temurin,java-version: 17) on GitHub Actions.
Frequently asked questions
Can I use Java 21 instead of 17?
Yes: "requires Java 17" is a minimum. Recent Android Studio versions actually bundle a JetBrains Runtime 21. Just check that your Gradle version supports that JDK.
Do I need to change sourceCompatibility or jvmTarget?
No, not for this error: it is about the Java running Gradle, not the bytecode version of your app. compileOptions and kotlinOptions.jvmTarget are separate settings.
Why does it work in Android Studio but not with flutter run?
Android Studio uses its Gradle JDK, while flutter run in a terminal uses JAVA_HOME or the JDK set with flutter config --jdk-dir. Align the two.
Useful tools for this error
More Mobile (Android, iOS) errors
- Fix "SDK location not found" (ANDROID_HOME / sdk.dir) on Android
- Fix "CocoaPods could not find compatible versions for pod" on iOS
- Fix "Unable to load script" (index.android.bundle) in React Native
- Fix "Signing for "App" requires a development team" in Xcode
- Fix "INSTALL_FAILED_UPDATE_INCOMPATIBLE: signatures do not match" on Android
- Fix "Duplicate class ... found in modules" in an Android Gradle build
- Fix "cmdline-tools component is missing" and "Android license status unknown" (flutter doctor)
- Fix "Invariant Violation: "main" has not been registered" (React Native / Expo)