47

Full Error --

An exception occurred applying plugin request [id: 'com.android.application']

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 C:\Program Files\Java\jdk-11.0.13 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.

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

Just Created the new project and getting this error.

codejockie
11.1k5 gold badges52 silver badges58 bronze badges
asked May 30, 2023 at 8:08
2
  • 1
    Does this help you? Commented May 30, 2023 at 8:13
  • Please provide enough code so others can better understand or reproduce the problem. Commented May 30, 2023 at 14:49

10 Answers 10

63

Step 1: Just Download the Java 17. LINK

Step 2: Set environment variable for Java 17.

Step 3: In Android Studio Go to File → settings → Build, Execution, Deployment → Build Tools → Gradle → Gradle JDK And Select Java 17.

Step 4: Delete the Gradle Cache directory if you still get the error, on Mac it's located at ~/.gradle/caches

BUILD SUCCESSFUL :)

Artiphishle
9109 silver badges16 bronze badges
answered May 30, 2023 at 8:39
Sign up to request clarification or add additional context in comments.

4 Comments

Note that there's no need to explicitly install a JDK when you can use the embedded JDK that ships with your Android Studio installation
There is no Gradle JDK option there. Android Studio 2021-2
I did it with the Embedded JDK as mention in the first comment. Take a look at this answer: stackoverflow.com/a/69064786/2597775. Also check your Gradle and AGP version. Mines are 8.0 and 8.0.2 respectively
Steps 14 and 15 from medium.com/@adityandar/… did the trick for me. Specially helpful if you are using an IDE different than Android Studio, i.e., VSCode.
23

If you use MacOS, here is this steps to check:

  1. In your terminal, run npx react-native doctor to check what is issue.

  2. This is issue: enter image description here

  3. Run brew install --cask zulu@17 to install OpenJDK

  4. Run brew info --cask zulu@17 to get path to where cask was installed.

  5. After you install the JDK. JDK will likely be at /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home

  6. Run npx react-native doctor to check again. enter image description here

Read more: https://reactnative.dev/docs/set-up-your-environment?platform=android

answered May 21, 2024 at 3:39

4 Comments

Thanks! This should be marked as the correct answer.
Works perfectly. Thanks
why is react-native required when the question has been tagged as Kotlin?
Sorry for replying with wrong tag. In my case using react-native, I also encountered the same case when installing JDK. Those who use react-native can verify again by this way.
7

In my case I downloaded gradle JDK version corretto-17 Amazon, and changed Gradle JDK version to corretto and it worked.

Not worked others(ex: jbr-17, embedded JDK Jetbrains 17 and etc.)

answered Jul 28, 2023 at 12:59

Comments

6

In my case, I was trying to run to a gradle wrapper command ./gradlew playstorepublish:installDist when I got that error. I followed the steps in the accepted answer but that only got me as far - it didn't fix the error. The next step I tried was to follow the third suggestion provided in error message:

changing org.gradle.java.home in gradle.properties.

I did this by opening the gradle.properties file and adding a new line with:

org.gradle.java.home=C\:\\Program Files\\Android\\Android Studio\\jbr

After doing this, I ran the command again and all was well again.

Or as pointed out in the comment:

org.gradle.java.home=C\:\\Program Files\\Java\\jdk-17
answered Apr 12, 2024 at 14:36

2 Comments

org.gradle.java.home=C\:\\Program Files\\Java\\jdk-17
Worth noting that there's also a gradle.propertiesfile in user's home directort (~/.gradle) and in my case it had precedence over the gradle.properties located inside the project.
2

If you're migrating from React Native 0.72 to 0.73, you'll need to update Java from version 17 to 21.
Download Java 21 and after installing it, open the environment variables and update JAVA_HOME to the path, typically located in C:/ProgramFiles/Java/jdk-{your version}.

Next, open Android Studio (I am using the latest version, Hedgehog). Follow these steps:

  • Go to File -> Project Structure.
  • In the mid-left section, you'll find a + icon. Click on it.
  • Select Download SDK and choose the compatible SDK version. You might get it by default else find compatible version and download after it finishes downloading.
  • Click Apply -> OK.
  • Then, open the terminal -> cd android -> Execute ./gradlew --version.
    It might start downloading compatible gradle version if not you'll see gradle version check if the gradle version is compatible to java version you downloaded then
    -> ./gradlew clean if the build is successful, you are ready to run app else if same error persists, run ./gradlew --stop run this twice -> rm -rf ~/.gradle/caches/* -> and try ./gradlew clean again.
dan1st
17.2k17 gold badges120 silver badges147 bronze badges
answered Dec 27, 2023 at 18:12

1 Comment

Read this and installed Java 21 due to this answer, which gave me compilation errors. I should have just checked the docs (reactnative.dev/docs/environment-setup) where they recommend a JDK version. Check the docs for the latest. Installed the recommended version, compiled fine with no other changes.
0

change jdk path in Environment Variables.

First Download jdk 17.0.10 JDK Download

  1. Type here to search-> Edit the system environment variables
  2. choose Advanced option -> Click on Environment Variables.
  3. In User Variables for **** -> Double click on JAVA_HOME.
  4. opened Edit User Variable.
  5. change variable value -> set path version 17.0.10(Downloaded latest jdk version).
  6. Then click ok and close all files and restart your computer.
  7. Finally Its work.
answered Apr 13, 2024 at 9:47

Comments

0

open your gradle.properties file and add the following line:

org.gradle.java.home={path to the JDK17 home directory}

e.g.
org.gradle.java.home=D:/Applications/Java/jdk-17.0.10

answered Apr 20, 2024 at 7:15

Comments

0

Ubuntu:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt install openjdk-17-jdk-headless

The last of the 3 commands shall upgrade and automatically switch to version 17 via update-alternatives. Now run java -version and you should see:

openjdk version "17.0.12" 2024年07月16日
OpenJDK Runtime Environment (build 17.0.12+7-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 17.0.12+7-Ubuntu-1ubuntu222.04, mixed mode, sharing)

Re-run your build and everything would run perfect.

answered Sep 2, 2024 at 11:44

Comments

0

For people encountering this issue with a React Native app on Windows:

The new environment variables setup instructions no longer require a JAVA_HOME variable. It originally pointed to the Android Studio jre.

If you follow the instructions from @noman-baig AND remove the JAVA_HOME entry in your environment variables the issue should be fixed.

answered Oct 25, 2024 at 13:46

Comments

0

For anyone stuck with this problem and Unity/Gradle just won't listen when you try to switch to Java 17, here's what worked for me:

  1. Go to C:\Program Files\Java

  2. Open the jdk-17 folder and copy everything inside.

  3. Find the JDK folder Unity says it's using (check the console error—mine was C:\Program Files\Java\jdk-16).

  4. Close Unity, then paste the contents of Java 17 into that folder, replacing everything.

  5. Open Unity again and try building.

Worst case, if some other program depends on the original Java 16, it might break—and you'll have to reinstall.

answered May 23, 2025 at 2:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.