【问题标题】:project built failed: Task 'compileDebug' is ambiguous in root project项目构建失败:任务“compileDebug”在根项目中不明确
【发布时间】:2015-06-14 22:52:30
【问题描述】:

在我将我的项目与 gradle 文件 同步后,一切正常,我在 gradle 控制台上收到 BUILD SUCCESSFUL 消息,但是当我运行我的项目时,我得到了这个留言:

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_05\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

当我运行堆栈跟踪时,我得到了这个:

FAILURE: Build failed with an exception.

* What went wrong:          
Task 'compileDebug' is ambiguous in root project 'PROJECT_NAME'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidT
estAidl', 'compileDebugAndroidTestJava', 'compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndr
oidTestSources', 'compileDebugJava', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugSources', 'compileDebugUnitTes
tJava', 'compileDebugUnitTestSources'.

* Try:                      
Run gradlew tasks to get a list of available tasks. Run with --info or --debug option to get more log output.

现在我不知道为什么会出现此错误。起初我在 libs 文件夹和 gradle 文件中添加了几个 jars 文件,它运行良好,没有错误,但现在由于某种原因它没有。即使我从 gradle 中删除了 jar,它仍然无法编译。因此,如果有人可以向我解释 compile debug 是什么意思以及为什么会出现此错误。

分级:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "PACKAGE_NAME"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
//    compile files('jsoup-1.8.1.jar')
//    compile files('ytd2.jar')
//    compile files('youtubeSearchApi.jar')
}

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="PACKAGE_NAME" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

【问题讨论】:

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


    【解决方案1】:

    我在运行任务时遇到了类似的问题:

    gradle compile
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Task 'compile' is ambiguous in root project 'testApp'. Candidates are:'compileJava', 'compileTestJava'.`
    

    我认为这是编译依赖项的问题,但这是任务本身的问题。我需要将任务运行为:

    gradle compileJava
    

    我最好的猜测是,如果您没有使用“gradle compileDebug”之类的命令,那么其中一个 android 配置正在执行该任务,并且它无法与您的 build.gradle 一起正常工作。

    这是一个似乎与您的问题特别相关的链接。 Click Here

    【讨论】:

      猜你喜欢
      • 2014-09-30
      • 2021-12-26
      • 2021-02-15
      • 2016-01-06
      • 1970-01-01
      • 2021-04-26
      • 2020-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多