首页 > 解决方案 > JAVA 错误:React 本机基本项目在 android studio 中不起作用

问题描述

我按照本文档中的所有步骤在 android studio 中安装和运行 react native 项目。

https://reactnative.dev/docs/environment-setup

当我在模拟器中运行命令npx react-native run-android以运行项目时,终端出现以下错误。

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 901 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
info Installing the app...
> Task :app:processDebugMainManifest FAILED
11 actionable tasks: 11 executed

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @6353fde6

* 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 16s

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 app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @6353fde6

* 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 16s

    at makeError (/var/www/html/test_native/node_modules/execa/index.js:174:9)
    at /var/www/html/test_native/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async runOnAllDevices (/var/www/html/test_native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
    at async Command.handleAction (/var/www/html/test_native/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:186:9)
info Run CLI with --verbose flag for more details.

环境:

Ubuntu 16.04
Node 14.15.4
Java 16
Latest Android Studio

环境变量:

JAVA_HOME="/usr/lib/jvm/jdk-16"

ANDROID_SDK_ROOT="/home/dev-21/Android/Sdk"

ANDROID_HOME="/home/dev-21/Android/Sdk"

标签: javaandroidreact-native

解决方案


今天有同样的问题,对我有用的是降级到 java 14,基于这个建议:https ://stackoverflow.com/a/66951023/1021253


推荐阅读