在项目':app'中找不到任务'installDebug'-创建项目后运行Android

时间:2020-03-27 19:09:05

标签: android react-native

创建一个react native项目后,我试图在我的android设备上运行它。我在终端输入adb devices,我看到了我的设备。我跑了react-native run-android。过了一会儿,Task 'installDebug' not found in project ':app'弹出了。

Jetifier found 962 file(s) to forward-jetify. Using 4 workers
...info Starting JS server...
'D:\Android\android-sdk\platform-tools' is not recognized as an internal or external command, operable program or batch file.
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings

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 15s

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.bat app:installDebug -PreactNativeDevServerPort=8
081

FAILURE: Build failed with an exception.

* What went wrong:
Task 'installDebug' not found in project ':app'.

这是反应性信息

info Fetching system and libraries information...
System:
    OS: Windows 7 6.1.7601
    CPU: (4) x64 Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz
    Memory: 881.91 MB / 3.97 GB
  Binaries:
    Node: 10.16.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.17.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
  IDEs:
    Android Studio: Version  3.2.0.0 AI-181.5540.7.32.5014246
  Languages:
    Python: Not Found
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0
    react-native: 0.62.0 => 0.62.0
  npmGlobalPackages:
    *react-native*: Not Found

我运行了gradlew tasks,但在安装任务下没有看到installDebug。我确定我正确设置了环境变量,包括android SDK,JDK。我尝试重新安装react-native。我将SDK的位置放在android文件夹下的local.properties中。我运行了gradlew installDebug,然后出现了installDebug not found in root project '[app's name]'。互联网上的所有解决方案都无效。

有人可以帮我解决这个问题吗? 谢谢。

4 个答案:

答案 0 :(得分:10)

我也面临着同样的问题。 这是对我有用的。

我在Android Studio中打开了Android项目。 可以位于YourReactNativeProjectFolder / android

当我在Android Studio中打开该项目时,它缺少配置。等待一段时间,让Android Studio对其进行配置,并要求您更新Gradle。更新Gradle,现在您可以从Android Studio或使用命令行“ npx react-native run-android

运行项目

我希望这会有所帮助。

最佳

答案 1 :(得分:2)

在项目根目录尝试以下命令:

cd android && ./gradlew assembleDebug && ./gradlew installDebug

答案 2 :(得分:2)

解决方案是在Android Studio中加载/ android文件夹,并让其更新Gradle。之后,您将可以运行react-native run-android

答案 3 :(得分:0)

这个问题最终发生在我将终端更改为ZSH时,这导致我的环境变量不再被识别。所以我要做的就是将〜/ .bash_profile中的所有内容复制到〜/ .zprofile中,并且可以正常工作。

参考:

https://www.aboutonline.info/2020/06/solved-task-installdebug-not-found-in.html