首页 > 解决方案 > 错误命令失败:gradlew.bat app:installDebug

问题描述

当我运行“react-native run-android”或“npx react-native run-android”或“cd andriod ./gradlew clean”这些命令时,错误会显示

PS D:\work\Myproject-app> npx react-native run-android
    info Starting JS server...
    Starting a Gradle Daemon, 2 incompatible and 2 stopped Daemons could not be reused, use --status                                 for details

    > Configure project :app
    Reading env from: .env

    FAILURE: Build completed with 2 failures.

    1: Task failed with an exception.
    -----------
    * What went wrong:
    A problem occurred evaluating project ':app'.
    > A problem occurred starting process 'command 'security''

    * Try:
    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.
    ==============================================================================

    2: Task failed with an exception.
    -----------
    * What went wrong:
    A problem occurred configuring project ':app'.
    > compileSdkVersion is not specified.

    * Try:
    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 19s
    error Could not install the app on the device, read the error above for details.
    Make sure you have an Android emulator running or a device connected and have
    set up your Android development environment:
    https://facebook.github.io/react-native/docs/getting-started.html
    error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details. 

我也尝试使用最新版本的 Gradle!

操作系统 Windows 10 节点:14.2.0 Java:java 版本“1.8.0_251” Java(TM) SE 运行时环境(内部版本 1.8.0_251-b08) Java HotSpot(TM) 64 位服务器 VM(内部版本 25.251-b08,混合模式) ) Gradle 版本:5.1.1

JAVA_HOME、ANDROID_HOME 和添加到环境的路径

标签: react-nativeandroid-studiogradlebuild.gradle

解决方案


我没有足够的代表发表评论,但是....

我今天遇到了这个问题。我的情况是该项目在 Mac 上运行良好。但是,我需要让它在 Windows 系统上运行。在我的 android\app\build.gradle 文件中,我设置了一个 getPassword 方法,它可以让我轻松签署我的 apk。在 getPassword 方法中,我有这个调用:

commandLine 'security', '-q', 'find-generic-password', '-a', currentUser, '-s', keyChain, '-w'

我注释掉了对 getPassword 方法的所有引用,它开始工作没有问题。

问题的根源在于 mac 使用的“安全”命令行工具在 Windows 上不可用。由于我现在还需要使用 Windows 框,因此我已经在外部凭据文件中配置了密码。


推荐阅读