当我在 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/