Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fix the error "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8." in React Native? #33416

Closed
wg-d opened this issue Mar 13, 2022 · 6 comments
Labels
Platform: Android Android applications. Resolution: Fixed A PR that fixes this issue has been merged. Resolution: Locked This issue was locked by the bot.

Comments

@wg-d
Copy link

wg-d commented Mar 13, 2022

Description

[admin@DF713 android % ./gradlew app:installDebug
FAILURE: Build failed with an exception.

  • Where:
    Build file '/Users/admin/Downloads/ritehauler-user/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.

I am running the command from zsh terminal.
Thanks.

Version

0.67.2

Output of npx react-native info

System:
OS: macOS 11.6
CPU: (4) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
Memory: 64.71 MB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.17.5 - ~/.nvm/versions/node/v14.17.5/bin/node
Yarn: 1.22.17 - ~/Downloads/ritehauler-user/node_modules/.bin/yarn
npm: 6.14.14 - ~/.nvm/versions/node/v14.17.5/bin/npm
Watchman: 2022.01.24.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.2 - /Users/admin/.gem/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
Android SDK:
API Levels: 28, 29, 32
Build Tools: 29.0.2, 32.1.0
System Images: android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-30 | Google Play Intel x86 Atom_64
Android NDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8092744
Xcode: 12.5/12E262 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_292 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.67.2 => 0.67.2
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

Run react-native run-android in project root directory.

Snack, code example, screenshot, or link to a repository

No response

@react-native-bot react-native-bot added the Platform: Android Android applications. label Mar 13, 2022
@cortinico
Copy link
Contributor

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

As the message says, you need to run on Java 11. You're probably running on Java 1.8.

The environment setup page on our website explains how to install Java 11:
https://reactnative.dev/docs/next/environment-setup

Closing here, but feel free to reopen if the issue is not solved.

@wg-d
Copy link
Author

wg-d commented Mar 13, 2022

Thanks! It's resolved now and I faced another issue.
#33417

@mMarcos208
Copy link

Thanks @cortinico

I updated jdk with flowing commands:

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

@muhammadashariabdillah24

Only for linux users

The first thing you have to do is install the JDK 11 package from oracle with the command

sudo apt-get install openjdk-11-jdk

Wait until the process is complete after that

type command

sudo apt-get update && sudo apt-get upgrade

and it worked

@iamabdulhaseeb
Copy link

iamabdulhaseeb commented Apr 28, 2022

Thanks @mMarcos208
brew tap homebrew/cask-versions
brew install --cask zulu11

this command worked for me.

@cortinico cortinico added Resolution: Fixed A PR that fixes this issue has been merged. and removed Needs: Triage 🔍 labels May 2, 2022
@gowthamcodes
Copy link

gowthamcodes commented May 18, 2022

in gradle.properties,
add following line,

org.gradle.java.home=C:/Program Files/Android/Android Studio/jre (refer to your path)

@facebook facebook locked as resolved and limited conversation to collaborators May 18, 2022
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: Android Android applications. Resolution: Fixed A PR that fixes this issue has been merged. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

7 participants