启动 Android studio 任务时出现 React-Native 错误:app:compileDebugJavaWithJavac FAILED

React-Native error when starting Android studio Task :app:compileDebugJavaWithJavac FAILED

我是 App Development 和 React-native 的新手,我正在尝试在 VS Code 中使用 'npx react-native run-android' 为 Android studio 启动模拟器,无论我做什么,我总是得到以下信息错误:

Starting a Gradle Daemon (subsequent builds will be faster)

> Task :app:compileDebugJavaWithJavac FAILED
15 actionable tasks: 2 executed, 13 up-to-date
Note: C:\Users\User\Testing\android\app\src\debug\java\com\testing\ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x247a2315) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x247a2315

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

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\User\Testing\android\app\src\debug\java\com\testing\ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x247a2315) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x247a2315

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

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

这是我的 build.gradle 文件:

buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"

我真的被困在这一点上任何帮助将不胜感激

问题是我安装了最新版本的 JDK (jdk-16.0.1) 导致错误,通过降级(到 jdk-15.0.2 ) 并再次更新我的系统变量,这为我解决了问题。