React-native run-android 在 MacOS 上失败

Jat*_*arg 6 macos android react-native

完整的控制台输出如下

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
info Installing the app...

FAILURE: Build failed with an exception.

* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

* 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 696ms

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

* 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 696ms

    at makeError (/Users/user/Desktop/sa/MyReactApp/node_modules/execa/index.js:174:9)
    at /Users/user/Desktop/sa/MyReactApp/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async runOnAllDevices (/Users/user/Desktop/sa/MyReactApp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
    at async Command.handleAction (/Users/user/Desktop/sa/MyReactApp/node_modules/@react-native-community/cli/build/index.js:186:9)
Run Code Online (Sandbox Code Playgroud)

bash_配置文件

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export ANDROID_SDK_ROOT=$ANDROID_HOME
export ANDROID_AVD_HOME=$HOME/.android/avd
alias emulator='$ANDROID_SDK_ROOT/tools/emulator'
Run Code Online (Sandbox Code Playgroud)

请求的附件

  1. 来自 Android Studio 的 Android SDK 链接

在此输入图像描述

  1. SDK工具已安装

在此输入图像描述

  1. npx @react-native-community/cli doctor 结果

在此输入图像描述

安装的 Android 模拟器 Nexus 6P(Android R 和 Pie)

React Native 的新功能在 iOS 上完美运行,但无法在 Android Simulator 中启动

尝试过的方法

  1. npm 启动
  2. npx 反应本机运行 ios
  3. npx 反应本机运行 android

Ris*_*hod 7

可能是因为上面提到的JDK版本。您可以通过运行 React Native Doctor 来验证

npx @react-native-community/cli doctor
Run Code Online (Sandbox Code Playgroud)


小智 2

安装 JDK 1.8 并设置 $JAVA_HOME 环境变量,然后尝试再次运行该应用程序。

该错误是由于JDK版本较低或未安装JDK造成的。