Failure on build with Gradle on command line with an android studio project : Xlint error

AndroidGradleAndroid Studiobuild.gradle

Android Problem Overview


When I try to build an android project with gradle with this command :

> gradlew clean build assembleRelease

It gives me this error :

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

I can build this project and make the APK in Studio.

Is there a way to configure Gradle to make a compilation ignoring Xlint notifications ?

OR, can I use other parameters, to make the release from command-line with gradle/gradlew ?

Android Solutions


Solution 1 - Android

It's a nice warning, not an error. To see the complete lint report you can add these lines to build.gradle:

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

If you really want to get rid of those warnings:

  1. Don't use deprecated API
  2. Use @SuppressWarnings("deprecation")

Solution 2 - Android

This is fairly obvious from @shakalaca's answer, but if you have code old enough to get the deprecation warning, you may also have code old enough to use unchecked operations, e.g. a List without the parameterized type as in List<String>. This will get you an additional warning:

Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

You can just expand the compiler args block to include that as well:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionam_technixView Question on Stackoverflow
Solution 1 - AndroidshakalacaView Answer on Stackoverflow
Solution 2 - AndroidSpanky QuigmanView Answer on Stackoverflow