首页 > 解决方案 > 在项目“:app”中找不到任务“installDebug”。仅在一个 react-native 项目中

问题描述

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

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

导航到项目(根目录)后,我首先使用 启动服务器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 变量。

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

感谢您的每一个帮助!

标签: androidreactjswindowsreact-nativerocket.chat

解决方案


我修好了它。没有一个解决方案有效,但我找到了另一种方法。

首先,不要忘记启动服务器。导航到项目的根文件夹并运行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 设备上成功启动。

祝你好运!:-)


推荐阅读