android - 无法使用android模拟器打开React Native项目

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

我是 React Native 的新手。我开始了一个新项目并遵循了所有步骤。我之前有 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

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

最佳答案

如前所述here ,你可以尝试在项目的根文件夹中运行以下命令:

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

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

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

如果即使在这之后您的所有项目都无法正常工作,请确保您的 PATH 变量中已经有 ANDROID_HOME 变量

关于android - 无法使用android模拟器打开React Native项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62190871/

相关文章:

java - 我必须在取消选中复选框时从数组列表中删除元素

android - HTML 邮件在 android gmail 客户端上不显示完整

android - 如何指示 Gradle 从不同位置使用 Java?

android - 错误 : Your cpu does not support required features(vt-x or svm) on AMD CPU under Windows

android - android中的Glassmorphism效果

javascript - PhoneGap 在应用程序浏览器中按后退键时未关闭

android - float 操作按钮未出现在 kitkat 中

android - 是否可以使用 React Native 构建 Android SDK 和 iOS SDK?

react-native - 如何减少 React Native 应用程序的启动时间

reactjs - React 导航不变违规 : Attempt to get native tag