How to recompile with -Xlint:deprecation

Andreas picture Andreas · Apr 7, 2018 · Viewed 48.1k times · Source

I don't use Android Studio but I build everything from the command line using build.gradle. I generate a Lint report like this:

./gradlew lint

This correctly generates a Lint report but it also says this:

Note: MyActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

This makes me wonder how I can do that? I've tried the following:

./gradlew lint -Xlint:deprecation

But it doesn't work. It says:

Problem configuring task :app:lint from command line.
Unknown command-line option '-X'.

So how can I pass -Xlint:deprecation to Lint via gradle?

Answer

Andreas picture Andreas · May 11, 2018

To answer my own question, you need to add the following to your project-level build.gradle file:

allprojects {
    ...

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