Display classes containing deprecation Android Studio

JavaAndroidAndroid StudioDeprecated

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

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

Solution 3 - Java

Looking at https://stackoverflow.com/questions/49711773/how-to-recompile-with-xlintdeprecation, 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
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhopemanView Question on Stackoverflow
Solution 1 - JavahopemanView Answer on Stackoverflow
Solution 2 - JavaSidhu GaikwadView Answer on Stackoverflow
Solution 3 - JavaCoolMindView Answer on Stackoverflow