编译时弃用警告

时间:2014-12-30 11:59:16

标签: android eclipse android-studio

我对开发环境设置有疑问。  我试图看看是否有可能使用不推荐使用的功能(可能是方法,构造函数或您能想到的任何东西)在development environment(eclipse,android studio) for android应用程序中进行编译警告。直到现在我正在手动找到这个已弃用功能的使用,我的老板让我在我的想法中寻找自动设置...

所以我想说一下特定的代码:

 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;
      }

我在这里有几个不推荐使用的功能,并且android studio声明了它,但我需要的是这个警告的配置是自动化的,并且省去了手动遍历每个类的需要......

2 个答案:

答案 0 :(得分:24)

选择分析>检查代码以在项目上运行lint。它应该检测任何已弃用的方法,以及项目中的其他常见错误。

您可以选择"按名称运行检查"在那里你可以找到"不推荐使用的API使用" (Java /代码成熟度问题)。

答案 1 :(得分:0)

对我来说,最好的解决方案是将以下行添加到文件build.gradle(project:appname)

allprojects {
tasks.withType(JavaCompile) {
    options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}

然后,java文件中所有不赞成使用的方法将显示在build选项卡中: deprecated api tab android studio

这适用于gradle 5.1.1

相关问题