How to Fix Android Gradle plugin requires Java 11 to run React Native Error

I was trying to run a new react native project using my Android emulator and I faced an unexpected react native issue that says the Android Gradle plugin requires Java 11 to run. Following is the complete error.

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/mohammedrashid/Documents/React Native/Side Projects/Phot/android/app/build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     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.

* Get more help at https://help.gradle.org

BUILD FAILED in 6m 32s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Note: /Users/mohammedrashid/Documents/React Native/Side Projects/Phot/node_modules/react-native-gradle-plugin/src/main/java/com/facebook/react/codegen/generator/SchemaJsonParser.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

The issue is with the JDK. As you can see, the error message is advocating us to use Java 11. Hence the solution is to use Java 11 instead of your outdated version of Java.

I use a Mac and hence I updated my JDK version using the following commands.

brew tap homebrew/cask-versions
brew install --cask zulu11

This fixed my issue and I was able to run my new react native project without errors.

Similar Posts

Leave a Reply