/ development

Android - Easily locating dependencies in Android Studio

When Android Studio came to replace the old Eclipse IDE, a great sigh was heard amongst Android developers around the globe. True project dependency, where a project can inherit the code and assets of another project, was now easily achievable. Long gone were the days of fighting with ANT to collect assets correctly.

But this raised a new issue. Since each of these subprojects is a separate module, each module comes with its own dependency tree. And those different trees might conflict.


There comes a time where you wonder why a certain library was included in your project, or why there are multiple conflicting versions of the same library.
Gradle comes with a great tool that allows you to investigate the dependency tree of your project and locate what gradle configuration and which module are responsible for a dependency.
The syntax is really simple:
gradle -q dependencyInsight --configuration CONFIGURATION_NAME --dependency DEPENDENCY_NAME

Example 1:

Let's find out where do I use Fresco in one of PeakApps' projects:
gradle -q dependencyInsight --configuration compile --dependency fresco produces the following result:

It's clear that 3 of my modules (peaksdk, app, ReactAndroid) rely on Fresco, and that there is no version conflict.

Example 2:

After an update to Google Services, Firebase suddenly appeared in one of PeakApps' projects. 2 different versions to be exact. So I wanted to find out the origin for this edition.
gradle -q dependencyInsight --configuration compile --dependency firebase produced the following result:
dependencyInsight result
This was interesting since it was clear that none of my modules explicitly uses Firebase. So why is it there? I'll answer this in a future post.