Display classes containing deprecation Android Studio
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.
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
Java -> Code maturity
Follow below steps: Go to Analyze -> Run Inspectinon By Name ->type Deprecated API Usage
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:
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
}
}