【问题标题】:Task 'installDebug' not found in root project 'Android'在根项目“Android”中找不到任务“installDebug”
【发布时间】:2019-05-21 13:31:32
【问题描述】:

“我正在使用命令行构建 android 项目,但 gradlew installDebug 命令出错。显示在根项目 'Android' 中找不到任务 'installDebug'”

我的顶级 build.gradle 文件:-

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我的模块级 build.gradle 文件是:-

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    defaultConfig {
        applicationId "com.avinash.myapplication"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:appcompat-v7:25.3.1'
}

【问题讨论】:

    标签: build.gradle


    【解决方案1】:

    第一步:

    不要使用react-native run-android

    第二步:

    如果您使用的是 Windows 并且没有文件 gradlew.bat(但只有 gradlew),请下载它 from here 或从另一个 react-native 项目中复制它。

    第三步:

    如果您在 Windows 上,则在目录 /android 中执行命令 gradlew tasksgradlew.bat tasks

    检查可以在安装任务中使用的命令

    Install tasks
    -------------
    installDevKernelDebug - Installs the DebugDevKernel build.
    installDevKernelDebugAndroidTest - Installs the android (on device) tests for the DevKernelDebug build.
    installProdKernelDebug - Installs the DebugProdKernel build.
    installProdKernelDebugAndroidTest - Installs the android (on device) tests for the ProdKernelDebug build.
    uninstallAll - Uninstall all applications.
    uninstallDevKernelDebug - Uninstalls the DebugDevKernel build.
    uninstallDevKernelDebugAndroidTest - Uninstalls the android (on device) tests for the DevKernelDebug build.
    uninstallDevKernelRelease - Uninstalls the ReleaseDevKernel build.
    uninstallProdKernelDebug - Uninstalls the DebugProdKernel build.
    uninstallProdKernelDebugAndroidTest - Uninstalls the android (on device) tests for the ProdKernelDebug build.
    uninstallProdKernelRelease - Uninstalls the ReleaseProdKernel build.
    Use the command gradlew installDevKernelDebug.
    

    第四步:

    如果您使用的是 react-native,请进入根目录并运行 npm startexpo start 如果您使用的是 expo。 在浏览器中转到http://localhost:19002(或控制台上显示的端口)。

    选择本地连接并恢复像 expXXXXXXXXXXXXXXXXXXXXX://127.0.0.1:19000.

    检查.\android\app\src\main\java\host\exp\exponent\generated\DetachBuildConstants.java 上的文件并复制DEVELOPMENT_URL 变量中的值。

    第五步:

    在控制台上使用 CTRL+C 退出 Metro Bundler。

    第 6 步:

    运行cd android进入./android/目录

    第 7 步:

    运行gradlew installDevKernelDebug 或您在步骤 3 中列出的其他任务。

    我在这个帖子上找到了大部分这些方向:https://github.com/expo/expo/issues/4097

    【讨论】:

      【解决方案2】:

      您可能缺少Android NDK,可以尝试使用Android-Studio 的SDK Manager 安装它。

      详情可以参考:https://stackoverflow.com/a/58987549/1435026

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-31
        • 1970-01-01
        • 1970-01-01
        • 2020-11-10
        • 2015-10-05
        • 2017-08-17
        • 2020-08-20
        相关资源
        最近更新 更多