当我在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")

10-08 13:48