【问题标题】:React Native project can't be open with android emulatorReact Native项目无法用android模拟器打开
【发布时间】:2020-09-23 05:10:50
【问题描述】:

我是一个反应原生的新手。我开始了一个新项目并遵循了所有步骤。我之前有 Android Studio,我用它启动了模拟器。运行npx react-native run-android 命令后出现此错误。

**FAILURE: Build failed with an exception.
* What went wrong:
Task 'installDebug' not found in project ':app'.
* Try:
Run gradlew tasks to get a list of available tasks. 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 34s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Task 'installDebug' not found in project ':app'.
* Try:
Run gradlew tasks to get a list of available tasks. 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 34s**

然后我运行abd -d 命令,我得到了这个。

Android Debug Bridge version 1.0.41
Version 29.0.6-6198805
Installed as C:\Users\User\AppData\Local\Android\Sdk\platform-tools\adb.exe

你能帮我解决这个问题吗?

【问题讨论】:

    标签: android react-native android-studio android-emulator


    【解决方案1】:

    here 所说,您可以尝试在项目的根文件夹中运行以下命令:

    cd android && ./gradlew installDevDebug && cd .. && react-native run-android --variant=DevDebug

    在此之后,您的项目应该可以在您的 Android 上成功运行。

    如果没有,用android studio打开你的项目一次,然后用react-native run-android重新编译

    如果即使在此之后您的所有项目都无法运行,请确保您的 PATH 变量中已经有 ANDROID_HOME 变量

    【讨论】:

    • 我的问题是在 PATH 变量中添加 ANDROID_HOME。感谢您的评论!!!
    猜你喜欢
    • 2020-07-21
    • 2019-05-07
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多