'"Task 'compile' is ambiguous in root project" - Android Studio
Every time I try to run my project, clean it or build it I get a gradle error:
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.
I have tried running gradle tasks with the options above (stacktrace,info,debug) but nothing helpful came up.
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
}
main gradle file:
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 file:
include ':app'
Screenshot of the problem:
Solution 1:[1]
Check the following :
Can you build and run another project? (New one for instance).
Try defining a debug buildType and resync gradle then build.
Check if you have a good proyect structure or set it in gradle.build if you don't.
If non of thoses work am out of ideas, sorry.
Solution 2:[2]
The problem is, your gradlew file is in the root of your project and you are trying to run an ambiguous task compile from the root of the project, in which the compiler does not know the actual task to run, this will lead to TaskSelectionException. You can run a single task, this stackoverflow question will help you
Solution 3:[3]
Remove the code
task clean(type: Delete) {
delete rootProject.buildDir
}
from your gradle file, then clean and rebuild your project.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kalem |
Solution 2 | Community |
Solution 3 | the_storyteller |