Skip to content
  1. LuzineDebug
  2. Mobile (Android, iOS)
  3. Android Gradle plugin requires Java 17 to run. Y…
Mobile (Android, iOS) Beginner ≈ 10 min to fix

Fix "Android Gradle plugin requires Java 17 to run"

Error message
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`.
In short

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).

Be the first to confirm this fix

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

  1. JAVA_HOME points to an old JDK: the build works in Android Studio but fails with ./gradlew, flutter run or npx react-native run-android.
  2. Wrong Gradle JDK in Android Studio: the project uses a separately installed JDK 11 instead of the JetBrains Runtime bundled with the IDE.
  3. Plugin upgrade: moving to AGP 8 (or a recent Flutter/React Native template) without changing JDK.
  4. Hard-coded org.gradle.java.home in gradle.properties pointing to an old JDK, or a CI image with Java 11.

Step-by-step fix

  1. See which Java Gradle uses

    Compare the java version, the JAVA_HOME value and the JVM reported by Gradle. On Windows, use gradlew.bat -version and echo $env:JAVA_HOME in PowerShell.

    bash
    java -version
    echo $JAVA_HOME
    cd android && ./gradlew -version
  2. 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-17 or jbr-21) or a JDK 17+. Then click Sync Project with Gradle Files.

  3. macOS / Linux terminal: point JAVA_HOME to a JDK 17

    Use the JDK bundled with Android Studio or install one (Temurin, OpenJDK). Add the export line to your ~/.zshrc or ~/.bashrc to make it permanent.

    bash
    # 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
  4. Windows terminal: set JAVA_HOME

    In PowerShell, setx saves the variable for future terminals; close and reopen your terminal (and your editor) afterwards.

    powershell
    setx JAVA_HOME "C:\Program Files\Android\Android Studio\jbr"
    # in a new terminal:
    & "$env:JAVA_HOME\bin\java" -version
  5. Flutter: tell it which JDK to use

    Flutter can use a specific JDK regardless of JAVA_HOME. Then check the "Java binary at" line of flutter doctor -v.

    bash
    flutter config --jdk-dir="/Applications/Android Studio.app/Contents/jbr/Contents/Home"
    flutter doctor -v
  6. 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.home is set in gradle.properties, fix or remove that line.

    bash
    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_HOME in your terminal.
  • Do not put a machine-specific org.gradle.java.home path in the committed gradle.properties: put it in ~/.gradle/gradle.properties if 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

All Mobile (Android, iOS) errors →