[英]Gradle detects Java 1.8 instead of Java 11
當創建一個新項目時
npx react-native init newProject
並通過以下方式啟動應用程序
npx react-native run-android
我會收到這個錯誤:
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
我已經嘗試過其他 gradle 版本和其他 react native 版本,但錯誤仍然存在。 現有項目正在運行...
您需要在系統上安裝 Java 11 並更新系統上的JAVA_HOME
和PATH
變量。 如果您使用的是 Windows,您可以在環境變量下添加或更新它。 對於基於 Linux 的系統,您只需將這些命令添加到您的配置文件中:
export JAVA_HOME="java11path"
export PATH=$JAVA_HOME/bin:$PATH
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.