In Progress
Status Update
Comments
ja...@gmail.com <ja...@gmail.com> #2
Related: issue 77234248
uc...@google.com <uc...@google.com> #3
Thank you for suggesting this enhancement. We value the feedback from our community and hope to review your suggestion in an upcoming sprint.
bu...@google.com <bu...@google.com>
ni...@gmail.com <ni...@gmail.com> #4
Is there any ETA for this?
is...@google.com <is...@google.com>
im...@google.com <im...@google.com>
ja...@gmail.com <ja...@gmail.com> #5
This would need to take into account class references from XML such as view nodes in layouts or actionViews from menus.
im...@google.com <im...@google.com> #6
There has been some work done this in the last few months - however only on the bytecode analyzer part. Things still left to do are the resources analyzer (incl. the class references but also it's possible no resources from a library are used either), and I don't think we're analyzing for strings in Class.forName() or reflection.
bu...@google.com <bu...@google.com>
ra...@gmail.com <ra...@gmail.com> #8
if it can help anyone, in the meanwhile, I did a hacky tool which removes dependencies one by one and checks if a specific gradle task runs.
https://github.com/r-cohen/unused-dep
im...@google.com <im...@google.com>
lu...@google.com <lu...@google.com>
[Deleted User] <[Deleted User]> #9
Someone mentioned my gradle plugin (https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin ), and I'd like to say that, while not a lint check, it does support the following:
1. Detecting unused dependencies
2. Detecting used transitive dependencies (which maybe you should declare directly)
3. Detecting dependencies on the wrong configuration (implementation vs api)
It has support for detecting android resources, although this does not work (currently, maybe ever) for merged R files. You have to be using namespaced R files (android.namespacedRClass=true).
It has automated tests verifying that it works for AGP 3.5.3, the latest 3.6.0 RC, and the latest 4.0.0 alpha, and Gradle 5.6.4 through 6.1.1.
1. Detecting unused dependencies
2. Detecting used transitive dependencies (which maybe you should declare directly)
3. Detecting dependencies on the wrong configuration (implementation vs api)
It has support for detecting android resources, although this does not work (currently, maybe ever) for merged R files. You have to be using namespaced R files (android.namespacedRClass=true).
It has automated tests verifying that it works for AGP 3.5.3, the latest 3.6.0 RC, and the latest 4.0.0 alpha, and Gradle 5.6.4 through 6.1.1.
lu...@google.com <lu...@google.com> #10
Since it isn't mentioned here, there is an experimental AGP task that can be invoked by running ./gradlew analyze<variant>Dependencies
that creates a JSON report of unused dependencies in build/intermediates/analyze_dependencies_report
. While it cannot be guaranteed that the tool will be fully reliable, it may be helpful for identifying possible unused dependencies.
Description
While tools like ProGuard and R8 will removed unused code, it's always a good idea to only depend on the minimal subset of required dependencies. So aside from manually poke-testing this by removing dependencies, it would be great to have Lint check this.
This is probably something that would be disabled by default as I suspect it involves quite a bit of work to validate. I assume it's just visiting every type reference in the module (both in classes, layouts, drawables, and manifest) and aggregating into a set and then validating that at least one type in each dependency is in that set.
Bonus points for supporting Class.forName() usage with a string literal argument!