【问题标题】:“任务'编译'在根项目中不明确” - Android Studio
【发布时间】:2016-01-06 00:29:13
【问题描述】:

每次我尝试运行我的项目、清理它或构建它时,我都会收到一个 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'

问题截图:

【问题讨论】:

  • 可以添加主模块的gradle文件吗?和 settings.gradle ?
  • 能否发一张模块设置的截图(快捷键F4)?和/或我在上述评论中询问的文件?
  • @Kalem 已发,请看,。
  • 看看这个stackoverflow.com/a/29834581/665823。换句话说,尝试使缓存无效并重新启动(File > Invalidate ..)
  • @Kalem 仍然无法正常工作......

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


【解决方案1】:

删除代码

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

从您的 gradle 文件中,然后清理并重建您的项目。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      检查以下内容:

      您可以构建并运行另一个项目吗? (例如新的)。

      尝试定义一个调试 buildType 并重新同步 gradle 然后构建。

      检查您是否有良好的项目结构,如果没有,请在 gradle.build 中设置。

      如果这些工作都没有想法,对不起。

      【讨论】:

        猜你喜欢
        • 2021-04-26
        • 2015-06-14
        • 1970-01-01
        • 1970-01-01
        • 2016-07-08
        • 2014-09-30
        • 1970-01-01
        • 1970-01-01
        • 2016-02-19
        相关资源
        最近更新 更多