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

跟風遠走 提交于 2019-11-29 02:51:21

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

  • Switch output 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']
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!