android - 在 Android studio 中使用 -Xlint 重新编译

标签 android android-studio gradle

当我在 Android Studio 中构建 Android 项目时,我收到消息:

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.

我想按照消息中的建议执行操作,但是如何执行呢?如何配置我的 Android studio 以按照上述消息的建议使用 -Xlint 重新编译我的项目? (我使用的是Android Studio 3.0.1)

最佳答案

该消息建议您使用 args -Xlint 重新编译以获得更多警告详细信息,将这些代码添加到 build.gradle:

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

然后您可以通过详细消息修复警告。
例如,您可以用新方法替换已弃用的方法(因为旧方法已被弃用,所以总是有新方法)。

但是,有时我们出于某种原因不想更改代码,只想摆脱编译警告,您可以在已弃用的方法前面添加 @SuppressWarnings("deprecation")

关于android - 在 Android studio 中使用 -Xlint 重新编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59843396/

相关文章:

php - 如何使用android studio将带有字符串数据的图像上传到mysql服务器

android - 用透明绘制半径角矩形

java - Android 两个网络同时操作

Android 应用程序使用 css 实现页面的通用 View

android - Android Studio 中的 Drawables 变红

groovy - Gradle脚本执行语义

android - Gradle : No tests found

java - Android Studio IDE 在 Ubuntu 15.04 上不显示对话框内容

spring - 使用Gradle下载Spring 4源

java - 查看 gradle 中单个配置的依赖树(使用 `dependencies` 任务)