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
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
@SuppressWarnings("deprecation") |
annotation.