大家好,我正在尝试创建和运行一个react原生应用程序。我运行npx react-native init rn4
,但当我运行npm run android
时,我有这个错误:
> Task :react-native-gradle-plugin:compileKotlin
'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\ReactExtension.kt: (10, 37): 'BaseVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\ReactExtension.kt: (119, 30): 'BaseVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\ReactExtension.kt: (135, 26): 'BaseVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\ReactExtension.kt: (155, 32): 'BaseVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\ReactExtension.kt: (161, 31): 'BaseVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\ReactExtension.kt: (169, 36): 'BaseVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\ReactPlugin.kt: (99, 48): 'reactRoot: DirectoryProperty' is deprecated. reactRoot was confusing and has been replace with rootto point to your root project and reactNativeDir to point to the folder of the react-native NPM package
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\TaskConfiguration.kt: (10, 37): 'ApplicationVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\TaskConfiguration.kt: (11, 37): 'BaseVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\TaskConfiguration.kt: (12, 37): 'LibraryVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\TaskConfiguration.kt: (28, 51): 'BaseVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\TaskConfiguration.kt: (131, 12): 'ApplicationVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\TaskConfiguration.kt: (132, 12): 'LibraryVariant' is deprecated. Deprecated in Java
w: C:\Users\emanu\App\rn4\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\TaskConfiguration.kt: (250, 14): 'BaseVariant' is deprecated. Deprecated in Java
> Task :react-native-gradle-plugin:compileJava
6 actionable tasks: 6 executed
Note: C:\Users\emanu\App\rn4\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.
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\emanu\App\rn4\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 59s
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.bat app:installDebug -PreactNativeDevServerPort=8081
Note: C:\Users\emanu\App\rn4\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.
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\emanu\App\rn4\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 59s
at makeError (C:\Users\emanu\App\rn4\node_modules\execa\index.js:174:9)
at C:\Users\emanu\App\rn4\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (C:\Users\emanu\App\rn4\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
at async Command.handleAction (C:\Users\emanu\App\rn4\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
我还运行了cd android && ./gradlew clean
,输出为:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\emanu\App\rn4\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`.
这是android/gradle/wrapper/gradle-wrapper.properties
中的文件
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
这是我运行./gradlew --version
时的输出
------------------------------------------------------------
Gradle 7.3.3
------------------------------------------------------------
Build time: 2021-12-22 12:37:54 UTC
Revision: 6f556c80f945dc54b50e0be633da6c62dbe8dc71
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 1.8.0_302 (Oracle Corporation 25.302-b08)
OS: Windows 10 10.0 amd64
我读过类似的帖子,但我还没有能够修复它。与文件夹,我创建了几天前,我没有问题,当我运行的应用程序。
有人能帮帮我吗?非常感谢!
7条答案
按热度按时间plicqrtu1#
如果您使用的是React Native witch Chocolatey,则必须将JDK版本更新为11。
要进行更新,请在PowerShell中执行以下命令(具有管理员权限):
在此之后,第一次(仅第一次)运行
npm android
时,您会得到大量警告,但项目的构建将工作。如果您继续收到错误,可能需要调整项目的gradle版本,使其与新的JDK版本兼容。
您可以通过编辑文件 *YOUR_PROJECT\android\gradle\wrapper\gradle-wrapper. properties * 来实现此目的
将分发URL的版本更新为7.4.2
我希望我对你有所帮助
yqlxgs2m2#
消息终于消失了。
在此之前,请执行以下操作[ iam using Mac]
1.安装JDK 11并设置HOME
1.如果您有任何旧版本或已安装最新的18,而不是在错误中提到的。然后按照这个URL删除安装,并确保路径设置正确,按照这个[参考得分最高的一个]
1.现在按照URL设置路径。由***Arv编写***
1.现在在android文件夹***android/.idea/compiler.xml***中查找此文件,并将目标集“1.8”更改为“11”x1c 0d1x
ycggw6v23#
我刚刚安装了jdk11,然后运行
cd ./android/ && ./gradlew clean
,这对我很有效agxfikkp4#
Android Gradle插件需要Java 11才能运行。您当前使用的是Java 1.8。
最后,您需要一个更新版本的Java来运行它。在线有许多资源可以帮助您完成这一任务。由于它推荐Java 11,我将坚持使用它。获得Java 11 for Windows的一个地方是Oracle downloads site(因为您目前有Oracle版本),但也有其他与OpenJDK相关的地方。
zed5wv105#
我在这里遇到了这个非常相同的问题。我尝试了MouTio的解决方案,并在Project-Name\android\gradle\wrapper\gradle-wrapper. properties中将发行版URL更新为7.4.2,但仍然出现以下错误:
“compileJava”任务(当前目标是1.8)和“compileKotlin”任务(当前目标是11)jvm目标版本1可操作任务:执行1例
失败:生成失败,出现异常。
无法查询任务":react-native-gradle-plugin:compileKotlin“属性”compilerRun Kotlin在Java安装中找不到所需的JDK工具。请确保Kotlin编译
但是,在使用管理权限通过命令行运行此
choco install -y nodejs-lts openjdk11
后,错误得到修复。别忘了用更新过的终端运行npm run android。
0s7z1bwu6#
仍然存在同样问题。
dwthyt8l7#
任务:react-native-gradle-plugin:compileKotlin“compileJava”任务(当前目标为1.8)和“compileKotlin”任务(当前目标为11)JVM目标兼容性应设置为相同的Java版本。
溶液
执行以下命令