【问题标题】:Failure on build with Gradle on command line with an android studio project : Xlint error使用 android studio 项目在命令行上使用 Gradle 构建失败:Xlint 错误
【发布时间】:2013-09-06 22:13:04
【问题描述】:

当我尝试使用此命令使用 gradle 构建 android 项目时:

> gradlew clean build assembleRelease

它给了我这个错误:

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.

我可以在 Studio 中构建这个项目并制作 APK。

有没有办法配置 Gradle 以编译忽略 Xlint 通知?

或者,我可以使用其他参数,通过 gradle/gradlew 从命令行发布吗?

【问题讨论】:

    标签: android gradle android-studio build.gradle


    【解决方案1】:

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

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

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

    1. 不要使用已弃用的 API
    2. 使用@SuppressWarnings("deprecation")

    【讨论】:

    • 在我的情况下,IDE 无法识别“选项”:(
    【解决方案2】:

    这在@shakalaca 的回答中是相当明显的,但是如果您的代码足够老可以收到弃用警告,您也可能有足够老的代码可以使用未经检查的操作,例如一个List,没有List&lt;String&gt; 中的参数化类型。这会给你一个额外的警告:

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

    【讨论】:

    • 如何在 Visual Studio 中执行此操作?
    猜你喜欢
    • 2012-10-19
    • 2013-08-17
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 2017-12-26
    • 2019-01-03
    相关资源
    最近更新 更多