问题描述
当我在Android Studio中构建Android项目时,我收到消息:
When I build my Android project in Android Studio, I get message:
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)
I would like to do what the message suggested, but how? How can I configure my Android studio to re-compile my project wihth -Xlint
as the above message suggested? (I am using Android Studio 3.0.1)
推荐答案
该消息建议您使用args -Xlint重新编译以获取更多警告详细信息,并将这些代码添加到build.gradle:
The message suggest you recompile with args -Xlint to get more warning details, add these code to build.gradle:
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
然后,您可以通过详细消息来修正警告.
例如,您可以使用新方法替换不推荐使用的方法(由于不推荐使用旧方法,因此始终有一个新方法).
Then you can fix warnings by detailed messages.
For example, you can replace deprecated method with new method(there always been a new method since old method has been deprecated) .
但是,有时由于某些原因我们不想更改代码,我们只是想摆脱编译警告,您可以在已弃用的方法前面添加@SuppressWarnings("deprecation")
.
However, sometimes we don't want change our code for some reasons, we just want get rid of compile warning, you can add @SuppressWarnings("deprecation")
in front of the deprecated method.
这篇关于在Android Studio中使用-Xlint重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!