Gradle build not working: Execution failed for task ':MyApp:compileDebug'

If you don't use Android Annotations but still cannot see what the reason is, you can actually do what the message says (check the compiler output) by:

  • going to the build tab

go to build tab

  • Switch output to compiler output

switch to compiler output


I finally found out what the problem was. The project uses Android Annotations, and I had included its generated sources folder in my build.gradle file.

When Gradle tried to generate the sources again, it would fail because of the duplicated classes.

Here's the correct build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs/main', include: '*.jar')
    compile project(':Libraries:LibProject1')
    compile project(':Libraries:LibProject2')
    compile project(':Libraries:LibProject3')
    compile project(':Libraries:LibProject4')
}

android {
    compileSdkVersion "Google Inc.:Google APIs:19"
    buildToolsVersion "19.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src/main/java', 'src-gen/main/java']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}