How to add -Xlint:unchecked to my Android Gradle based project?

rfgamaral picture rfgamaral · Sep 9, 2013 · Viewed 58k times · Source

I tried to add the following to the root build.gradle file:

subprojects {
    gradle.projectsEvaluated {
        tasks.withType(Compile) {
            options.compilerArgs << "-Xlint:unchecked -Xlint:deprecation"
        }
    }
}

But I'm getting this:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Libraries:ActionBarSherlock:compileRelease'.
> invalid flag: -Xlint:unchecked -Xlint:deprecation

What am I doing wrong?

Answer

Felipe Lima picture Felipe Lima · Mar 4, 2014

This is what worked for me: (in your project's build.gradle)

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
        }
    }
}