在项目 ':app' 中找不到任务'installDebug'。仅在一个 react-native 项目中



我是React的新手,第一次尝试做Hello World项目。我得到了上面提到的错误,但也有错误,我的sdk路径没有设置。所以我配置了一个ANDROID_SDK_ROOT变量。然后它正常工作。

现在我想在我的安卓设备上运行github的火箭聊天应用程序。这是一个项目:https://github.com/RocketChat.

导航到项目(root(后,我首先用npm start启动服务器,并向我显示了一条成功的消息。然后我想用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 1m 5s
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

我知道已经有一些关于这个错误的帖子了,到目前为止我尝试了他们的解决方案,但还没有成功。

我的设备已注册,并且在执行adb devices时显示。还设置了全局android sdk变量。

可能出了什么问题?有人能告诉我我缺了什么吗?

谢谢你的帮助!

我修复了它。所有解决方案都不起作用,但我找到了另一种方法。

首先,不要忘记启动服务器。导航到项目的根文件夹并运行npm start。这应该会成功运行。如果它说您的端口已经使用,只需打开您的任务管理器并终止NodeJS中的所有任务。

在android文件夹中,运行命令gradlew tasks。这将显示可用命令的列表。我不知道为什么,但命令installDebug不在那里,因此出现了错误。

但也有其他类似的任务,例如installFossDebug

所以我运行了npx react-native run-android --variant=installFossDebug。但它不起作用。控制台显示了一个新错误,显示为Task installInstallFossDebug could not be found(No Typo(。

我不知道为什么install在任务中出现了两次,所以我只运行了npx react-native run-android --variant=FossDebug,瞧,它起了作用。该应用程序在我的android设备上成功启动。

祝你好运!:-(

最新更新