How to recompile with -Xlint:deprecation

55,518

Solution 1

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"
        }
    }   
}

Solution 2

Just an update from me since I ran into this issue recently:

You can get the details for this deprecation issue by doing as @Andreas suggested in the accepted answer. If you're using Kotlin, the real solution is (in build.gradle):

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

One other solution is to update your AndroidSDK. The issue is with an SDK method overriding a deprecated feature. In your build.gradle file you can change the compileSdkVersion:

android {
    compileSdkVersion 29 //Change this to the latest release
    ...
    ...

    defaultConfig {
        ...
        targetSdkVersion 29 //Change this too
        ...
    }
}

Using the latest SDK version will likely fix your issue. Android does a good job of fixing deprecation issue between releases. If it persists, you might just need to wait until the next SDK release. If the issue isn't in the AndroidSDK but instead in a package you've downloaded, you should see if the package needs upgrading or contact the manager of that package.

Share:
55,518
Andreas
Author by

Andreas

Updated on July 09, 2022

Comments

  • Andreas
    Andreas almost 2 years

    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?