在根项目“ Android”中找不到任务“ installDebug”

时间:2019-05-21 13:31:32

标签: build.gradle

“我正在使用命令行构建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'
}

2 个答案:

答案 0 :(得分:0)

步骤1:

请勿使用react-native run-android

步骤2:

如果您使用的是Windows,但没有文件gradlew.bat(只有gradlew),请下载文件from here或从其他本机项目中复制它。

第3步:

在/ android目录中,如果您使用的是Windows,请执行命令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.

步骤4:

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

选择本地连接并恢复值,例如 expXXXXXXXXXXXXXXXXXXX://127.0.0.1:19000。

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

步骤5:

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

步骤6:

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

步骤7:

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

我在此线程上找到了大多数这些指导:https://github.com/expo/expo/issues/4097

答案 1 :(得分:0)

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

有关详细信息,请参阅:https://stackoverflow.com/a/58987549/1435026