【问题标题】:'installDebug' not found in root project 'android' React Native在根项目“android”React Native 中找不到“installDebug”
【发布时间】:2016-12-31 08:27:23
【问题描述】:

我正在尝试在 android 模拟器上运行我的项目。当我运行react-native run-android 时,我得到以下信息:

FAILURE: Build failed with an exception.

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

* 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.

BUILD FAILED

如果我运行./gradlew tasks,我会得到:

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'android'.
components - Displays the components produced by root project 'android'. [incubating]
dependencies - Displays all dependencies declared in root project 'android'.
dependencyInsight - Displays the insight into a specific dependency in root project 'android'.
help - Displays a help message.
model - Displays the configuration model of root project 'android'. [incubating]
projects - Displays the sub-projects of root project 'android'.
properties - Displays the properties of root project 'android'.
tasks - Displays the tasks runnable from root project 'android'.

知道为什么我的项目中没有 installDebug 任务吗?如何找回?

【问题讨论】:

  • 你有解决办法吗,我也遇到同样的问题

标签: android react-native


【解决方案1】:

react-native run-android --variant [productFlavorName][debug/release]

例如 react-native run-android --variant Huaweidebug

【讨论】:

  • 您可以通过解释他们的项目中为什么没有 installDebug 任务以及您建议的解决方案将如何解决他们的问题来提高您的回答质量。
【解决方案2】:

用于调试测试

react-native run-android --variant devKernelDebug

原因是因为在文件 android/build.gradle 我们有这个

  productFlavors {
    devKernel {
      dimension 'remoteKernel'
    }
    prodKernel {
      dimension 'remoteKernel'
    }
  }

【讨论】:

    【解决方案3】:

    我在新的 react-native 项目 (react-native init projectname) 在 running react-native start 然后在 VS 代码中 react-native run-android 之后遇到了同样的问题。它给出了这个错误

    Task 'installDebug' not found in project ':app'.
    

    它在 RN“0.62.1”中

    解决方案:- 我打开 Android Studio,然后清理并重建。

    我不确定它在清理和重建后是否会起作用。

    我也做了并给出了根项目中的 sdk 路径

    export ANDROID_HOME=/home/mycomputer/Android/Sdk/
    export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
    

    然后就可以了。

    我的 npm 版本 6.7.0 我的节点版本 v11.10.1 react-native-cli: 2.0.1 反应原生:0.62.1

    【讨论】:

    • 您能说明这个“清理和重建”选项在哪里吗?我有完全相同的错误,但我找不到这个选项。另外,您将 SDK 路径添加到哪个文档?
    • 打开 Android Studio 并打开您的项目。我认为它在启动时会同步 Gradle,之后,您将在 android studio 的上方标签栏中看到 Build。有一个 Clean 项目和一个 Rebuild 项目。对于 SDK 路径,我使用的是 Ubuntu。当我用SDK安装android studio包时,安装后会在桌面方向创建Android目录,我得到SDK的路径。使用上面的代码在终端中给出路径。我从一个给出路径的 stackoverflow 问题中找到了它。
    【解决方案4】:

    我已经解决了这个问题你只需要在Android文件夹中创建文件

    转到安卓文件夹

    创建文件local.properties

    然后只需在 local.properties 文件中添加此代码:-

    如果您使用的是 MacBook,那么 sdk.dir=/Users/USERNAME/Library/android/sdk

    如果您使用的是 Windows,则 sdk.dir=C:\Users\USERNAME\AppData\Local\Android\sdk

    如果您使用的是 Linux,那么 sdk.dir = /home/USERNAME/Android/sdk

    如果你想知道你的系统用户名是什么,那么只需使用 Mac whoami 的命令

    然后只需重新运行命令 react-native run-android

    谢谢:)

    【讨论】:

    • 谢谢。对我来说效果很好,但不知何故我不得不在我的窗口上添加一个双斜杠:sdk.dir=C:\\Users\\USERNAME\\AppData\\Local\\Android\\Sdk。但是添加local.properties 文件以及sdk.dir 参数绝对是我必须做的。
    【解决方案5】:

    我也遇到了这个问题,还有一个问题

    此版本中使用了已弃用的 Gradle,使其与 摇篮 7.0。

    在 Android 构建中,如所附屏幕截图所示。

    在使用 android studio 打开 android 文件夹并让它由 android studio 构建时,问题正在得到解决。之后在运行

    npx react-native run-android

    ,它工作正常。

    【讨论】:

      【解决方案6】:

      用android studio打开项目,会自动修复问题

      【讨论】:

      • 为什么会修复它?仅在使用 Android Studio(而不是使用 ./gradlew installDebug)编译时尝试修复与丢失的 .so 文件相关的问题
      • 项目的根目录包含在 ./gradlew 中,有时您可能会丢失这些文件或根目录不正确,因此要修复这些问题,只需通过 android studio 打开项目即可。跨度>
      【解决方案7】:
      cd android
      ./gradlew clean
      cd..
      react-native run-android --variant=DevDebug
      

      这对我来说是固定的

      【讨论】:

      • 谢谢!我在运行./gradlew clean 时确实遇到了后续错误:Failed to install the following Android SDK packages as some licences have not been accepted stackoverflow.com/a/43003932/6168487
      【解决方案8】:

      只需更改此设置,转到此文件夹和文件,

      node_modules/react-native/local-cli/runAndroid/runAndroid.js

      installdebug 替换为

      } else { gradleArgs.push('installDevDebug'); }

      【讨论】:

        【解决方案9】:

        以下命令解决了我的问题:

        运行--> ./android 文件夹中的 gradlew :app:installDebug

        安装后运行 gradlew tasks 列出可用的任务。在那里你可以检查

        安装任务

        installDebug - 安装调试版本。

        installDebugAndroidTest - 为 Debug 构建安装 android(在设备上)测试。

        uninstallAll - 卸载所有应用程序。

        uninstallDebug - 卸载调试版本。

        uninstallDebugAndroidTest - 卸载 Debug 版本的 android(设备上)测试。

        uninstallRelease - 卸载 Release 版本。

        【讨论】:

        • 它现在使用gradle 而不是gradlew 运行。
        【解决方案10】:

        我知道这是一个老问题,但以防万一:今天在 react-native 项目中遇到同样的问题,请仔细检查您的 ANDROID_HOME 环境变量是否设置为本地 SDK 文件夹。

        你可以试试“react-native doctor”看看发生了什么;但它是有道理的:没有 ANDROID_HOME,react-native 只是不知道要构建什么,所以你不能运行任何东西。

        【讨论】:

          【解决方案11】:

          我对 react native 也有同样的问题。最终能够通过遵循 rest-native 文档中的确切环境设置指南来解决问题。浏览以下 URL 中的文档。祝你好运。 enter link description here

          【讨论】:

            【解决方案12】:

            我正在粘贴代码以显示run-android 的一些可用选项

            var _default = {
              name: 'run-android',
              description: 'builds your app and starts it on a connected Android emulator or device',
              func: runAndroid,
              options: [{
                name: '--root [string]',
                description: 'Override the root directory for the android build (which contains the android directory)',
                default: ''
              }, {
                name: '--variant [string]',
                description: "Specify your app's build variant",
                default: 'debug'
              }, {
                name: '--appFolder [string]',
                description: 'Specify a different application folder name for the android source. If not, we assume is "app"',
                default: 'app'
              }, {
                name: '--appId [string]',
                description: 'Specify an applicationId to launch after build.',
                default: ''
              }, {
                name: '--appIdSuffix [string]',
                description: 'Specify an applicationIdSuffix to launch after build.',
                default: ''
              }, {
                name: '--main-activity [string]',
                description: 'Name of the activity to start',
                default: 'MainActivity'
              }, {
                name: '--deviceId [string]',
                description: 'builds your app and starts it on a specific device/simulator with the ' + 'given device id (listed by running "adb devices" on the command line).'
              }, {
                name: '--no-packager',
                description: 'Do not launch packager while building'
              }, {
                name: '--port [number]',
                default: process.env.RCT_METRO_PORT || 8081,
                parse: val => Number(val)
              }, {
                name: '--terminal [string]',
                description: 'Launches the Metro Bundler in a new window using the specified terminal path.',
                default: (0, _cliTools().getDefaultUserTerminal)()
              }, {
                name: '--tasks [list]',
                description: 'Run custom Gradle tasks. By default it\'s "installDebug"',
                parse: val => val.split(',')
              }, {
                name: '--no-jetifier',
                description: 'Do not run "jetifier" – the AndroidX transition tool. By default it runs before Gradle to ease working with libraries that don\'t support AndroidX yet. See more at: https://www.npmjs.com/package/jetifier.',
                default: false
              }]
            };
            

            希望回答对你有帮助

            【讨论】:

              【解决方案13】:

              解决办法很简单——

              1. 在 Android Studio 中打开 react-native 应用的 android 文件夹。
              2. 选择应用文件夹并点击菜单 -> 构建 -> 重新构建。
              3. 如果它要求更新或一些建议的操作,请全部接受。
              4. 最重要的是,修改gradlew.bat文件的权限。为此,请在终端中打开 react-native 应用程序并运行 -
              chmod +x android/gradlew.bat 
              

              然后最后运行-

              npx react-native start
              
              npx react-native run-android
              

              【讨论】:

                【解决方案14】:

                以下命令为我解决了 Linux 上的问题。您应该将 ~/Android/Sdk 替换为您自己的 Android SDK 路径。

                export ANDROID_SDK_ROOT=~/Android/Sdk
                

                【讨论】:

                  【解决方案15】:

                  在 Android Studio 中打开 React Native 项目的 android 文件夹,对我来说它是自动生成的

                  local.properties

                  其中包含 sdk.dir

                  然后回到你的 React Native 项目的根目录并运行

                  yarn android
                  

                  【讨论】:

                    【解决方案16】:

                    我遇到了同样的错误。我刚刚打开 VS Code 并在 android 文件夹中,我创建了 local.properties 文件,然后添加了sdk.dir=/Users/apple/Library/Android/sdk(不要复制我的,你可以找到你的 sdk 路径在安卓工作室)。后来,我跑了npx react-native run-android,这解决了我的问题。

                    【讨论】:

                      【解决方案17】:

                      以下步骤对我有用:

                      右键单击“android”文件夹,然后单击“在集成终端中打开”

                      运行“gradlew tasks”命令。

                      向下滚动到“安装任务”部分:

                      该列表将包含您将针对 run-android 命令传递的变体。以“installExperimentalFossDebug”任务为例,变体将是“ExperimentalFossDebug”。

                      下一步是使用该变体在项目的根目录(不在 android 文件夹中)运行“运行 android”命令。

                      npx react-native run-android  --variant ExperimentalFossDebug
                      

                      按照上述步骤,您将能够针对模拟器运行项目:

                      【讨论】:

                        【解决方案18】:

                        你必须在android目录下运行gradlew

                        这是一个例子。运行以下命令,它将产生与 OP 提到的相同的输出。

                        ./android/gradlew tasks
                        

                        那就试试吧:

                        cd android
                        ./gradlew tasks
                        

                        输出完全不同。我不知道为什么会这样。

                        【讨论】:

                          【解决方案19】:

                          当项目基于风味构建时会出现错误。

                          当您需要为不同的客户端构建相同的应用程序时,Flavors 是一种解决方案,例如一个用于 Facebook,一个用于 Microsoft,并且您必须对代码进行一些细微的调整。更多关于口味的信息:https://blog.logicwind.com/adding-multiple-target/

                          所以,要解决这个问题,对于Android系统,去android/app/build.gradle

                          现在找到下一部分:

                          android {
                          
                          ...
                          
                          flavorDimensions "default"
                          
                          productFlavors {
                              dev {
                                  minSdkVersion rootProject.ext.minSdkVersion
                                  applicationId 'com.myproject.dev'
                                  targetSdkVersion rootProject.ext.targetSdkVersion
                                  resValue "string", "build_config_package", "com.myapp"
                              }
                              prod {
                                  minSdkVersion rootProject.ext.minSdkVersion
                                  applicationId 'com.myproject'
                                  targetSdkVersion rootProject.ext.targetSdkVersion
                                  resValue "string", "build_config_package", "com.myapp"
                              }
                              facebook {
                                  minSdkVersion rootProject.ext.minSdkVersion
                                  applicationId 'com.myproject.facebook'
                                  targetSdkVersion rootProject.ext.targetSdkVersion
                                  resValue "string", "build_config_package", "com.myapp"
                              }
                          }
                          
                          defaultConfig {
                              applicationId "com.myproject"
                              minSdkVersion rootProject.ext.minSdkVersion
                              targetSdkVersion rootProject.ext.targetSdkVersion
                              versionCode 1
                              versionName "1.0"
                          }
                          ...
                          }
                          

                          正如您在 productFlavors 标签中看到的,我们有 3 种不同的构建版本(dev、prod 和 facebook)。现在,这些风格中的每一种都有两种不同的运行时模式(或构建)(调试和发布)。因此,正如其他人所建议的,当您构建应用程序时,您必须指定要构建的风格。

                          接下来需要使用的命令是:

                          npx react-native run-android --variant <productFlavour><BuildType>
                          

                          查看 build.gradle,对于这个项目,我们有下一个可能的变体:

                          devDebug 和 devRelease, prodDebug 和 prodRelease, facebookDebug 和 facebookRelease

                          根据您的配置,只需调整 productFlavor 就可以了

                          【讨论】:

                            【解决方案20】:

                            Android studio中打开Android文件夹,它会自动下载所有需要的文件

                            【讨论】:

                              【解决方案21】:

                              从 android/app/build.gradle 中移除 productFlavors 代码

                              【讨论】:

                                猜你喜欢
                                • 1970-01-01
                                • 1970-01-01
                                • 1970-01-01
                                • 2022-07-08
                                • 1970-01-01
                                • 1970-01-01
                                • 1970-01-01
                                • 1970-01-01
                                • 2022-08-21
                                相关资源
                                最近更新 更多