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.
- changingorg.gradle.java.homeingradle.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.
-
1Does this help you?Mirco0– Mirco02023年05月30日 08:13:59 +00:00Commented May 30, 2023 at 8:13
-
Please provide enough code so others can better understand or reproduce the problem.Community– Community Bot2023年05月30日 14:49:22 +00:00Commented May 30, 2023 at 14:49
10 Answers 10
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 :)
4 Comments
If you use MacOS, here is this steps to check:
In your terminal, run
npx react-native doctorto check what is issue.This is issue: enter image description here
Run
brew install --cask zulu@17to install OpenJDKRun
brew info --cask zulu@17to get path to where cask was installed.After you install the JDK. JDK will likely be at /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home
Run
npx react-native doctorto check again. enter image description here
Read more: https://reactnative.dev/docs/set-up-your-environment?platform=android
4 Comments
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.)
Comments
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
2 Comments
gradle.propertiesfile in user's home directort (~/.gradle) and in my case it had precedence over the gradle.properties located inside the project.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 SDKand 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 cleanif the build is successful, you are ready to run app else if same error persists, run./gradlew --stoprun this twice ->rm -rf ~/.gradle/caches/*-> and try./gradlew cleanagain.
1 Comment
change jdk path in Environment Variables.
First Download jdk 17.0.10 JDK Download
- Type here to search-> Edit the system environment variables
- choose Advanced option -> Click on Environment Variables.
- In User Variables for **** -> Double click on JAVA_HOME.
- opened Edit User Variable.
- change variable value -> set path version 17.0.10(Downloaded latest jdk version).
- Then click ok and close all files and restart your computer.
- Finally Its work.
Comments
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
Comments
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.
Comments
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.
Comments
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:
Go to
C:\Program Files\JavaOpen the
jdk-17folder and copy everything inside.Find the JDK folder Unity says it's using (check the console error—mine was
C:\Program Files\Java\jdk-16).Close Unity, then paste the contents of Java 17 into that folder, replacing everything.
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.
Comments
Explore related questions
See similar questions with these tags.