使用 Xlint:在 Android 中弃用
因此,当我编译 Android 应用程序时,我几乎总是收到这样的消息:
[javac] Note: /home/kurtis/sandbox/udj/androidApp/src/org/klnusbaum/udj/PlaylistFragment.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
如何使用此选项重新编译?我必须在 build.xml 中编辑某些内容吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这些属性也可以在 Ant 命令行上定义,避免编辑:
ant "-Djava.compilerargs=-Xlint:unchecked -Xlint:deprecation" debug
要启用所有 Lint 警告:
ant - djava.compilerargs=-Xlint 调试
These properties can also be defined on the Ant command line, avoiding edits:
ant "-Djava.compilerargs=-Xlint:unchecked -Xlint:deprecation" debug
To enable all Lint warnings:
ant -Djava.compilerargs=-Xlint debug
甚至更简单,无需复制完整的 javac 目标:将以下行放入 ant.properties 文件中:
这样,它只需覆盖 Android SDK 默认构建配置中的 java.compilerargs 即可。 (顺便说一句,您可以自己检查默认情况下它是空的)。 SDK 更新不会造成混乱,可能会在不通知您的项目的情况下更改默认 javac 目标。
只是一种更细粒度的方法! :)
Even simpler and without the need to copy a complete javac target: put the following line in ant.properties file :
This way, it just overrides java.compilerargs from Android SDK default build configuration. (You can check for yourself that it is empty by default, btw). No mess with SDK update that could change the default javac target without your project being notified.
Just a more granular way to do! :)
是的,根据 build.xml 文件中的以下声明,如果您想要...
这意味着:
转到 $ANDROID_SDK_ROOT/tools/ant/main_rules.xml 文件并复制“编译”目标。
将其粘贴到 build.xml 文件中的 之前。
然后将以下元素添加到任务中:
同样,您可以添加其他编译器选项,例如未检查的操作:
Yes, per the statement below in the build.xml file, if you want to ...
That means:
Go to the $ANDROID_SDK_ROOT/tools/ant/main_rules.xml file and copy the "compile" target.
Paste it into your build.xml file before the <setup/> task.
Then add the following element to the task:
Likewise, you can add other compiler options, such as for unchecked operations:
看起来您应该只能在项目文件夹根目录的
build.properties
或ant.properties
中指定选项。我尝试了这个,但似乎不起作用。我想避免编辑
build.xml
文件,因为如果您需要更新项目,这会在以后增加复杂性。但是,我无法找到解决方法。但是,我没有复制整个compile
目标,而是在文件底部的
import
行之前添加了:。It looks like you should just be able to specify the option in either
build.properties
orant.properties
in the root of your project folder. I tried this and it didn't seem to work.I wanted to avoid editing my
build.xml
file as this adds complication later if you need to update your project. However, I was unable to find a way around it. However, rather than copying the wholecompile
target I added:just before the
import
line at the bottom of the file.如果你想拥有一个良好的 CI + CD 管道并且你关心你的代码质量,显示有关 lint 抱怨的更多信息的一个好选择是将其添加到你的 top/root gradle.build 中:
或者
如果你只想添加一个选项(您通常会添加更多),在任务
JavaCompile
中,您只需添加:It's 2018,您可以依靠 Gradle 来设置它。我只添加了两个编译器参数选项,但还有更多。您可以在此处和此处。
If you want to have a good CI + CD pipeline and you care about your code quality, a good option to show more information about lint complainings is by adding this to your top/root gradle.build:
or
If you only want to add one option (you would normally add more), inside the task
JavaCompile
you just need to add:It's 2018 and you can rely on Gradle to set this up. I only added two compiler argument options but there are much more. You can find more information here and here.