eclipse 编译时不推荐使用的警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27705085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
deprecated warning while compiling
提问by TubusMan
i have a question regarding development environments settings.
i am trying to see if there is any possibility to make a compilation warning in a development environment(eclipse,android studio)
for android applications using a deprecated feature(could be a method , constructor or whatever you can think of ). until now i am working manually to find the use of this deprecated features , and my boss asked me to look for an automatic settings in my idea ...
我有一个关于开发环境设置的问题。我想看看是否有可能在development environment(eclipse,android studio)
使用不推荐使用的功能(可能是方法、构造函数或任何你能想到的)的 android 应用程序中发出编译警告。直到现在我都在手动工作以找到这个已弃用功能的使用,我的老板让我在我的想法中寻找自动设置......
so lets say for a specific code :
所以让我们说一个特定的代码:
protected void onPrepareDialog(int paramInt, Dialog paramDialog)
{
try
{
super.onPrepareDialog(paramInt, paramDialog);
AlertDialog localAlertDialog = (AlertDialog)paramDialog;
localAlertDialog.setTitle("Passphrase required");
((TextView)localAlertDialog.findViewById(2131230727)).setText(Preferences.getConfigName(this, getConfigFile()));
Button localButton = localAlertDialog.getButton(-3);
if (this.mOpenVpnService != null);
for (boolean bool = true; ; bool = false)
{
localButton.setEnabled(bool);
return;
}
i have several deprecated features here , and android studio declares it , but what i need is a configuration for this warning to be automated and save me the need of walking through each class manually ...
我在这里有几个不推荐使用的功能,并且 android studio 声明了它,但是我需要的是一个配置来使这个警告自动化并省去我手动遍历每个类的需要......
回答by Nuwisam
Select Analyze > Inspect Codeto run lint on your project. It should detect any deprecated methods, as well as others common mistakes in your project.
选择“分析”>“检查代码”以在您的项目上运行 lint。它应该检测任何已弃用的方法,以及项目中的其他常见错误。
You can select "Run inspection by name" and there you can find "Deprecated API usage" (Java / Code maturity issues).
您可以选择“按名称运行检查”,然后您可以找到“已弃用的 API 使用”(Java / 代码成熟度问题)。
回答by Evilripper
For me the best solution is add this lines in the file build.gradle(project:appname)
对我来说,最好的解决方案是在 build.gradle(project:appname) 文件中添加这一行
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
Then all the deprecated methods in the java files appear in the build tab: deprecated api tab android studio
然后java文件中所有不推荐使用的方法出现在构建选项卡中: deprecated api tab android studio
This works on gradle 5.1.1
这适用于 gradle 5.1.1