Home » Android » android – deprecated warning while compiling

android – deprecated warning while compiling

Posted by: admin May 14, 2020 Leave a comment


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 …

so lets say for a specific code :

 protected void onPrepareDialog(int paramInt, Dialog paramDialog)
      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)

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 …

How to&Answers:

Select Analyze > Inspect Code to run lint on your project. It should detect any deprecated methods, as well as others common mistakes in your project.

You can select “Run inspection by name” and there you can find “Deprecated API usage” (Java / Code maturity issues).


For me the best solution is add this lines in the file 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

This works on gradle 5.1.1