[英]Gradle detects Java 1.8 instead of Java 11
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 ./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.我已经尝试过其他 gradle 版本和其他 react native 版本,但错误仍然存在。 Existing projects are working...现有项目正在运行...
You need to install Java 11 on your system and update the JAVA_HOME
and PATH
variables on your system.您需要在系统上安装 Java 11 并更新系统上的JAVA_HOME
和PATH
变量。 If you are using Windows, you can add or update it under environment variables.如果您使用的是 Windows,您可以在环境变量下添加或更新它。 For Linux-based systems, you can just add these commands to to your profile file:对于基于 Linux 的系统,您只需将这些命令添加到您的配置文件中:
export JAVA_HOME="java11path"
export PATH=$JAVA_HOME/bin:$PATH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.