Recompile with -Xlint in Android studio

Staying out of deprecated methods is useful, so your app won’t run in some compatibility mode on the device. Plus having clean build output is also nice 🙂

While building an app, Gradle may produces some warnings telling you that some input files are using unchecked or unsafe operations or they are overriding a deprecated API.

Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

As the message suggest, we should recompile with -Xlint to get more details about the warnings.

In the app level build.gradle file

app level build.gradle file

we should add a section labelled  allprojects{}(if not already present).

In the allprojects{} section we will instruct Gradle to apply custom compiler arguments for each task involving  Java code compilation.

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

Now each time we build our app we will get detailed output of the unchecked or unsafe operations and the deprecated API we are using.

Tip: if for some reason we want to continue using a deprecated API and just suppress the warnings, we could annotate the deprecated method with the



Related Post

Every opacity value hex code I often work with HEX colors and want to apply some alpha to them. Calculating the exact alpha HEX value is tedious job so here it is: the complete l...
Auto ‘versionCode’ increment when buil... Since I adopted Fabric as a way to monitor vital app stats such as 'Time in App per User' and it's Beta distribution platform to distribute test build...
Settings.canDrawOverlays() allays returns ‘f... I was updating one of my clients app, and testing it how it behaves on Android O (API 26). The app requires permissions to draw over system windows (a...
Java: Parts of the Day A handy utility method that will return the part of the day, such as morning, afternoon, evening, etc. public static String getPartOfTheDay(final...
GSM Signal Monitor 1.5 out now! GSM Signal Monitor 1.5 is out now! This version features new app visual style, additional logging options, bug fixes and Android 5.x and up support...
Alien Swarm 1.4.1 out now! Alien Swarm version 1.4.1 is out now! This is the best ‘Alien Swarm’ release to date. Featuring Facebook and Google+ share integration, so you ...
If you liked this article and think it is useful use the buttons below.


  1. tasks.withType(JavaCompile) {
    options.compilerArgs << “-Xlint:unchecked” << “- } = Error

    tasks.withType(JavaCompile) {
    options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"}
    = OK

    Android Gradle Plugin = 3.5.0
    Gradle Version = 5.4.1

Leave a Reply

Your email address will not be published. Required fields are marked *