59

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 ?

4

2 回答 2

93

这是一个很好的警告,而不是错误。要查看完整的 lint 报告,您可以将这些行添加到 build.gradle:

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

如果您真的想摆脱这些警告:

  1. 不要使用已弃用的 API
  2. 使用 @SuppressWarnings("deprecation")
于 2013-09-11T14:23:55.637 回答
43

这从@shakalaca 的回答中是相当明显的,但是如果您的代码足够老来获得弃用警告,那么您可能也有足够老的代码来使用未经检查的操作,例如List没有参数化类型的代码,如List<String>. 这会给你一个额外的警告:

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

您也可以扩展编译器 args 块以包含它:

allprojects {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
    }
}
于 2014-05-12T18:41:52.277 回答