繁体   English   中英

react-native run-android 失败 MacOS

[英]react-native run-android Fails MacOS

完整的控制台 Output 如下

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)

bash_profile

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'

请求的附件

  1. Android SDK 链接来自 Android Studio

在此处输入图像描述

  1. SDK 工具安装

在此处输入图像描述

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

在此处输入图像描述

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

New To React Native 它在 iOS 上完美运行,但无法在 Android 模拟器中启动

尝试过的方法

  1. npm启动
  2. npx react-native 运行-ios
  3. npx react-native run-android

可能是因为上面提到的JDK版本。 您可以通过运行 react native doctor 来验证

npx @react-native-community/cli doctor

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

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

只需按照以下步骤即可解决您的问题: 将 node_modules 依赖项喷射/转换为 AndroidX 假设您有一个 react-native 项目。 您的库依赖项之一转换为 AndroidX。,您需要使用新版本。

因此,现在您需要将您的应用程序转换为 AndroidX,但是您的许多 react-native 库都附带原生 Java 代码并且尚未更新。 这是怎么做的?

First, use Android Studio's refactoring tool to convert your app re: the Android developer docs npm install --save-dev jetifier npx jetify npx react-native run-android (your app should correctly compile and work) Call npx jetify run in the postinstall target of你的 package.json (任何时候你的依赖更新你都必须再次jetify

您也可以点击此链接: https://www.npmjs.com/package/jetifier

随意任何困惑。

这个链接是完整的解决方案,但如果你有win32,这里有一个小问题,但如果你有win64,你对go很好。

 **https://www.npmjs.com/package/jetifier#do_you_need_this**

希望这个答案对您有任何问题都可以随意使用。

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

我认为您需要在以下部分解决:

用android studio打开android文件夹

然后文件-> 项目结构-> SDK 位置,在这里您可以更改,在我的情况下,我更改版本在此处输入图像描述

在此之前,要知道错误是什么:

我意识到这个命令有什么问题

npx @react-native-community/cli doctor

我收到了这些错误: 在此处输入图像描述

请按照以下说明进行更改以解决此错误。

安装Java SDK版本:14以上。

JDK下载链接: https://www.oracle.com/java/technologies/javase-jdk14-downloads.html

gradle-wrapper.properties请使用 6.3 或更高版本。

例如: distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM