76

I updated my project to the latest Android APIs and the project now has multiple deprecated methods. Does Android Studio have a cool way of listing all classes containing said methods, such as the TODO window? I know I can go through every class and search methodically through the code, but I would rather like to make it easy on myself.

TylerH
  • 20,799
  • 66
  • 75
  • 101
hopeman
  • 2,778
  • 3
  • 18
  • 33

4 Answers4

128

If it helps someone else heres the answer to my question:

If you go to Analyze -> Inspect Code...

When your project has been inspected click on Code maturity issues and tada, there is a list of all Deprecated API usages :)

UPDATE: May 2021

Deprecation warnings are now found under your respective language.

Kotlin -> Migration -> Usage of redundant or deprecated syntax or deprecated symbols

Kotlin deprecation

Java -> Code maturity

Java deprecation

hopeman
  • 2,778
  • 3
  • 18
  • 33
  • 13
    It doesn't show deprecated methods ("Code maturity issues" is not listed). – CoolMind Jan 22 '21 at 15:14
  • @CoolMind in your IDE you can go to **File -> Editor -> Inspection** Please make sure that you have ticked **Code maturity under Java** and **Migration under Kotlin**. – Abdullqadir Jun 01 '23 at 07:24
72

Follow below steps: Go to Analyze -> Run Inspectinon By Name ->type Deprecated API Usage

In the latest Android Studio 2021.3.1+ Go to Code -> Analyze Code -> Run Inspectinon By Name ->type Deprecated API Usage

Samrakchan
  • 342
  • 3
  • 15
Sidhu Gaikwad
  • 749
  • 5
  • 2
  • 2
    Please make sure your minSdkVersion value is proper. This tool will show all the deprecated APIs in source code below the minSdkVersion value. – Faisal T Dec 06 '17 at 10:07
4

Looking at How to recompile with -Xlint:deprecation, add into root build.gradle:

allprojects {
    ...
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.encoding = 'UTF-8'
            options.compilerArgs << "-Xlint:deprecation"
        }
    }
}

or in build.gradle.kts:

allprojects {
    ...
    gradle.projectsEvaluated {
        tasks.withType<JavaCompile> {
            options.compilerArgs.add("-Xlint:deprecation")
        }
    }
}

Then start in Terminal:

./gradlew lint

or in Gradle menu:

enter image description here

It will show warnings, but also can fail after 3 errors:

Caused by: org.gradle.api.GradleException: Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:

android {
    lintOptions {
        abortOnError false
    }
}

The first 3 errors (out of 4) were:

Adding these lines in app/build.gradle won't help. You should fix all errors and try to launch Lint again.

If you have many errors, you can show all of them:

android { 
    lintOptions { 
        // abortOnError false 
        // if true, stop the gradle build if errors are found
        isAbortOnError = false
        // if true, show all locations for an error, do not truncate lists, etc.
        isShowAll = true
    }
}
CoolMind
  • 26,736
  • 15
  • 188
  • 224
1

Right click on your app folder (module) with "Android" selected in the Project explorer and then go to Analyze -> Inspect Code...

It will run for a few minutes and then show you deprecated classes as well as other things you might want to fix.

Micro
  • 10,303
  • 14
  • 82
  • 120