When creating a new project with
npx react-native init newProject
and start the app by
npx react-native run-android
I will receive this error:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\path\newProject\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.
Your current JDK is located in C:\Program Files\OpenJDK\openjdk-8u292-b10\jre
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 11s
error Failed to install the app. Make sure you have the Android development environment set u
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
./gradlew --version
------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------
Build time: 2022-08-05 21:17:56 UTC
Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918
Kotlin: 1.6.21
Groovy: 3.0.10
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 1.8.0_292 (Oracle Corporation 25.292-b10)
OS: Windows 10 10.0 amd64
I have tried it with other gradle versions and other react native versions, but the error still persists. Existing projects are working...
CodePudding user response:
You need to install Java 11 on your system and update the JAVA_HOME
and PATH
variables on your system.
If you are using Windows, you can add or update it under environment variables. For Linux-based systems, you can just add these commands to to your profile file:
export JAVA_HOME="java11path"
export PATH=$JAVA_HOME/bin:$PATH