gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:45:52 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com