PC パソコン

How to Fix Android Studio “Android Gradle plugin requires Java”

When you open a project in Android Studio or run Gradle Sync or a build,
an error called
“Android Gradle plugin requires Java”
may be displayed.

This error occurs when the Java version required by the Android Gradle Plugin
does not match the version of the JDK currently being used by Gradle.

It may occur especially when the Android Gradle Plugin has been updated,
when Android Studio has been updated,
or when an old Android project is opened in a newer environment.

This article explains the main causes and solutions
when “Android Gradle plugin requires Java” is displayed in Android Studio.

What Is “Android Gradle plugin requires Java”?

“Android Gradle plugin requires Java” is an error displayed
when the Java environment requirements are not met,
such as when the version of the JDK actually used by Gradle
is older than the Java version required by the Android Gradle Plugin being used.

The error message may display
the required Java version.

Android Gradle plugin requires Java 17 to run.
You are currently using Java 11.

In this example,
Java 17 is required to run the Android Gradle Plugin,
but Java 11 is currently being used.

Point:
With this error,
it is important to check not only whether a newer version of Java is installed on the PC,
but also which JDK Android Studio’s Gradle is actually using.

Main Causes

The main causes of
“Android Gradle plugin requires Java”
in Android Studio include the following.

  • The Gradle JDK version is old
  • Only the Android Gradle Plugin was updated
  • An old JDK is still selected after updating Android Studio
  • The combination of Gradle and JDK is incompatible
  • The system Java and Android Studio’s Gradle JDK are different
  • JAVA_HOME points to an old JDK
  • An old Android project was opened in a newer Android Studio
  • Multiple JDKs are installed
  • Different JDKs are used on the command line and in Android Studio
  • An old Java version is being used in a CI or automated build environment

Check the Java Version Displayed in the Error Message

First,
check the full error message.

The Java version required by the Android Gradle Plugin
and the Java version currently being used
may be displayed as follows.

Android Gradle plugin requires Java 17 to run.
You are currently using Java 11.

In this case,
you need to change the JDK used by Gradle
to Java 17 or a supported later version.

Check the Java Version Currently Being Used

You can check the Java version being used by the system
from Terminal or another command-line environment.

java -version

For example,
if Java 11 is being used,
information about Java 11 will be displayed.

However,
the Java displayed here
is not necessarily the same as the JDK used by Gradle in Android Studio.

Check the Java Used by Gradle

You can use the Gradle Wrapper
to check the JVM actually used by Gradle.

./gradlew --version

On Windows,
depending on the environment,
run the following.

gradlew.bat --version

You can check the Java version used by Gradle
from the JVM section or other information displayed.

Check the Gradle JDK in Android Studio

Android Studio allows you to configure
the JDK used by Gradle separately.

Even if a newer Java version is displayed by the system’s
java -version,
an older Gradle JDK may be selected on the Android Studio side.

Open the Gradle settings in Android Studio
and check the currently selected Gradle JDK.

Select a JDK that corresponds to
the Java version required by the Android Gradle Plugin.

Change the Gradle JDK

If a JDK older than the Java version displayed in the error is selected,
change the Gradle JDK to a supported version.

For example,
if the Android Gradle Plugin requires Java 17,
select a JDK corresponding to Java 17 as the Gradle JDK.

After making the change,
run Gradle Sync again.

Use the JDK Bundled with Android Studio

Android Studio may include a bundled JDK.

Selecting the JDK bundled with Android Studio as the Gradle JDK
may reduce problems caused by version differences
from Java installed externally.

However,
you need to check whether the Android Gradle Plugin and Gradle being used
support that JDK.

Check Whether the Required JDK Is Installed

If the JDK for the Java version required by the Android Gradle Plugin
is not installed on the PC,
you need to prepare the corresponding JDK.

After installing the JDK,
select the newly installed JDK
as the Gradle JDK in Android Studio.

Simply installing the JDK
may not automatically change the setting in Android Studio.

Check the Android Gradle Plugin Version

The required Java version may differ
depending on the Android Gradle Plugin version.

Depending on the project,
the Android Gradle Plugin version may be specified as follows.

plugins {
    id("com.android.application") version "8.5.0" apply false
}

In older project formats,
it may be configured as follows.

classpath 'com.android.tools.build:gradle:8.5.0'

If the error occurred immediately after updating the Android Gradle Plugin,
check the Java version required by the new Android Gradle Plugin.

If Only the Android Gradle Plugin Was Updated

If only the Android Gradle Plugin is changed to a newer version,
it may no longer work with the JDK that was previously used.

As a result,
“Android Gradle plugin requires Java” may be displayed.

In this case,
change to the JDK required by the Android Gradle Plugin,
or return the Android Gradle Plugin
to a previous supported version if necessary.

Downgrade the Android Gradle Plugin

If you cannot change to a newer JDK due to the environment being used,
returning the Android Gradle Plugin
to a previous version that supports the current Java environment
may resolve the problem.

However,
changing the Android Gradle Plugin also affects compatibility with Gradle,
so check the Gradle version as well.

Note:
If you change only Java,
only the Android Gradle Plugin,
or only Gradle independently,
another compatibility error may occur.
Make changes while checking the combination of
JDK, Gradle, and Android Gradle Plugin.

Check the Gradle Version

If you change the JDK,
also check whether the Gradle being used supports that Java version.

The Gradle version can normally be checked
in the following file.

gradle/wrapper/gradle-wrapper.properties

Check the
distributionUrl
in the file.

distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip

If Gradle is too old for the JDK being used,
Gradle itself may need to be updated.

Check the Combination of JDK, Gradle, and Android Gradle Plugin

In an Android project,
the three versions of
JDK,
Gradle,
and Android Gradle Plugin
are related to each other.

Even if the Android Gradle Plugin is new,
it may not work correctly if Gradle or the JDK is old.

Conversely,
if only the JDK or Gradle is made newer than necessary,
a compatibility problem with the Android Gradle Plugin may occur.

Therefore,
it is important to use a compatible combination of all three.

If It Occurred After Updating Android Studio

When Android Studio is updated,
the JDK used by Gradle
or the recommended Android Gradle Plugin environment may change.

If “Android Gradle plugin requires Java” occurred
immediately after updating Android Studio,
check the Gradle JDK setting.

If the old JDK that was previously used remains selected,
change it to a supported JDK.

When Opening an Old Project in a Newer Android Studio

An old Android project may be configured
on the assumption that an older Android Gradle Plugin,
Gradle,
and JDK are being used.

If you open the project in a newer Android Studio
and update only the Android Gradle Plugin,
the Java requirements may change
and this error may occur.

In this case,
rather than changing JDK,
Gradle,
and Android Gradle Plugin
all to the latest versions at once,
update them in order while checking their compatibility.

Do Not Confuse the System Java with the Gradle JDK

If multiple JDKs are installed on the PC,
the Java used in Terminal
and the Java used by Gradle in Android Studio may be different.

In Terminal,
you can check Java with the following command.

java -version

You can check the Java actually used by Gradle
with the following command.

./gradlew --version

If the two results are different,
check the Gradle JDK and environment variables in Android Studio.

Check JAVA_HOME

If you run Gradle from the command line,
the
JAVA_HOME
setting may affect the result.

If
JAVA_HOME
points to an old JDK,
Gradle may run with an older Java version
even if a newer JDK is installed.

If it works correctly in Android Studio
but an error occurs when running it from Terminal,
check
JAVA_HOME.

If Multiple JDKs Are Installed

If multiple JDKs such as Java 11,
Java 17,
and Java 21 are installed on the PC,
an unintended JDK may be selected.

Check the Gradle JDK in Android Studio,
JAVA_HOME,
and
java -version
in Terminal individually.

Check whether the Java version required by the Android Gradle Plugin
matches the Java actually used by Gradle.

Run Gradle Sync Again

After changing the Gradle JDK,
Android Gradle Plugin,
or Gradle settings,
run Gradle Sync again.

Run
Sync Project with Gradle Files
or a similar option from Android Studio.

If the previous error is still displayed after changing the settings,
the new settings may be loaded through Sync.

Run Clean Project

Even after changing the JDK or Gradle settings,
old build information may remain.

Run
Clean Project
from the Build menu or another location in Android Studio,
and then run Gradle Sync or Rebuild Project.

Restart Android Studio

If the previous state remains
even after changing the Gradle JDK,
restart Android Studio.

After restarting,
run Gradle Sync
and check whether the newly selected JDK is being used.

If the Error Occurs Only on the Command Line

You may be able to build normally from Android Studio,
while an error occurs only when running
./gradlew
from Terminal.

In this case,
the Gradle JDK in Android Studio
and the
JAVA_HOME
or Java settings on the Terminal side
may be different.

Check
java -version
and
./gradlew --version,
and compare the Java versions actually being used.

If It Occurs in a CI or Automated Build Environment

Even if it works correctly in the local Android Studio environment,
“Android Gradle plugin requires Java”
may occur in a CI or automated build environment.

In this case,
check the Java version being used in the CI environment.

If different JDKs are used in the local environment and CI environment,
the build results may differ even for the same project.

What to Check for Each Error

Depending on the Java- or Gradle-related error,
you can narrow down what should be checked to some extent.

Displayed Message Main Points to Check
Android Gradle plugin requires Java Gradle JDK, JDK, Android Gradle Plugin
Unsupported class file major version JDK, Gradle, Android Gradle Plugin
Minimum supported Gradle version is … Gradle Wrapper, Android Gradle Plugin
incompatible version of the Android Gradle plugin Android Studio, Android Gradle Plugin, Gradle
Gradle sync failed Detailed error, compatibility among JDK, Gradle, and plugins

Steps to Check If the Problem Is Not Resolved

If you do not know the cause,
checking the following in order makes it easier to narrow down the problem.

  1. Check the full “Android Gradle plugin requires Java” error message
  2. Check the required Java version
  3. Check the Java version currently being used
  4. Check java -version
  5. Check the Gradle JDK in Android Studio
  6. Check the JVM used by Gradle with ./gradlew --version
  7. Check the Android Gradle Plugin version
  8. Check the Gradle Wrapper version
  9. Check the compatibility among JDK, Gradle, and Android Gradle Plugin
  10. Change the Gradle JDK to a supported JDK if necessary
  11. Change the Android Gradle Plugin or Gradle if necessary
  12. Check JAVA_HOME
  13. Check whether multiple JDKs are installed
  14. Run Gradle Sync again
  15. Run Clean Project if necessary
  16. Restart Android Studio if necessary

Important:
If “Android Gradle plugin requires Java” is displayed,
rather than simply changing Java to the latest version,
it is important to check the JDK required by the Android Gradle Plugin
and the JDK supported by Gradle,
and use a compatible combination of
JDK, Gradle, and Android Gradle Plugin.

Summary

Android Studio’s
“Android Gradle plugin requires Java”
is an error displayed when the Java version required by the Android Gradle Plugin
does not match the JDK actually used by Gradle.

It may occur especially when only the Android Gradle Plugin is updated,
when Android Studio is updated,
or when an old project is opened in a newer development environment.

First, check the required Java version displayed in the error message,
and then check the Java actually being used
with the Gradle JDK in Android Studio
and
./gradlew --version.

Then,
check the versions of
JDK,
Gradle Wrapper,
and Android Gradle Plugin,
change them to a compatible combination,
and run Gradle Sync again
to efficiently narrow down the cause.