android - "Task ' 编译 ' is ambiguous in root project"- Android Studio

标签 android android-studio gradle android-gradle-plugin

每次我尝试运行我的项目、清理它或构建它时,我都会收到 gradle 错误:

Error:FAILURE: Build failed with an exception.

* What went wrong:
Task 'compile' is ambiguous in root project 'FifiFun2'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl', 'compileDebugAndroidTestJavaWithJavac', 'compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugSources', 'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources', 'compileLint', 'compileReleaseAidl', 'compileReleaseJavaWithJavac', 'compileReleaseNdk', 'compileReleaseRenderscript', 'compileReleaseSources', 'compileReleaseUnitTestJavaWithJavac', 'compileReleaseUnitTestSources'.

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

我已经尝试使用上述选项(stacktrace、info、debug)运行 gradle 任务,但没有任何帮助。

渐变:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

主gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.user_pc.myapplication"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
}

settings.gradle 文件:

include ':app'

问题截图:

enter image description here

最佳答案

问题是,您的 gradlew 文件位于项目的根目录中,而您正试图从项目的根目录运行一个模棱两可的任务编译,其中编译器不知道要运行的实际任务,这将导致到任务选择异常。您可以运行单个任务,这 stackoverflow question will help you

关于android - "Task ' 编译 ' is ambiguous in root project"- Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33014852/

相关文章:

android - Gradle 依赖项 : Get latest snapshot from remote repo

android - 从后台线程访问 View 尺寸

java - 使用计数器进行评分

android - Android Studio隐藏 native 源文件夹子目录中的文件

android - AChartEngine 和 Android Studio

java - 使用 gradle 迁移到 Java 11;不支持的操作异常

gradle - CompileJava找不到元模型并且失败

java - 错误: MyGestureDetector cannot be resolved to a type.如何解决?

java - Fragment 和 Android 生命周期

android - 在 android 的数据库中存储用户组的最佳想法