DEV Community

Cover image for How to Show Library Dependency Tree in Android Studio?
Vincent Tsen
Vincent Tsen

Posted on • Updated on • Originally published at vtsen.hashnode.dev

How to Show Library Dependency Tree in Android Studio?

Different ways to show library dependencies used by your app in Android Studio using gradlew command.

One of the things I struggle in Android development is to understand the dependencies' relationship among all the libraries that I use. Sometimes, if you don't include certain library dependency, and it still works? Why? It is because of the implicit dependency that has been included by other libraries that you use.

In this article, I'm going to show the different ways of showing or displaying library dependencies in Android Studio.

1. Gradle Tool Windows

  • Go to View -> Tool Windows -> Gradle or click the Gradle tab in the top right corner of your Android Studio How_to_Show_Library_Dependencies_Tree_in_Android_Studio_01.JPG

The problem with this method is it doesn't show the dependencies tree. All dependencies are flattened, which makes it a bit harder to figure out certain library relationships.

2. Command-line Dependency Tree

  • In the terminal window, run the following command
gradlew -q app:dependencies --configuration debugRuntimeClasspath
Enter fullscreen mode Exit fullscreen mode
  • -q is used so that it has the clean output (no logging information printed)
  • --configuration is used to show only certain configuration dependencies. If this is omitted, all configurations' dependency will be included which we don't want

This the command-line output:
How_to_Show_Library_Dependencies_Tree_in_Android_Studio_02.JPG

Tip 1: If you failed to run the command above, you may need to update the JAVA_HOME environment variable to the correct JDK path (i.e. <Androud Studio Installed Path>\jre). Changing it from Settings->Build, Excecution, Deployment->Build Tools -> Gradle in Android studio doesn't seem to work.

Tip 2: if you failed again due to the following error gradlew : The term 'gradlew' is not recognized as the name of a cmdlet, function, script file, or operable program. You need to specify the ".\" in front of the gradlew command.

.\gradlew -q app:dependencies --configuration debugRuntimeClasspath
Enter fullscreen mode Exit fullscreen mode

3. Web-based Dependency Tree Report

  • In the terminal window, run the following command
gradlew app:dependencies --configuration debugRuntimeClasspath --scan
Enter fullscreen mode Exit fullscreen mode
  • --scan is added at the end and -q is removed from the previous command.
  • -q removal is required in order to work correctly
  • When you see this, type yes and click enter.
Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https://gradle.com/terms-of-service. Do you accept these terms? [yes, no]
Enter fullscreen mode Exit fullscreen mode
  • Click the link below the Publishing build scan... How_to_Show_Library_Dependencies_Tree_in_Android_Studio_03.JPG
  • Enter your email address How_to_Show_Library_Dependencies_Tree_in_Android_Studio_04.JPG
  • Click this link as shown below once you receive the email How_to_Show_Library_Dependencies_Tree_in_Android_Studio_05.JPG

Now, you can view the web-based dependency tree report!
How_to_Show_Library_Dependencies_Tree_in_Android_Studio_06.JPG

4. Local HTML - Project Report Plugin

Another web-based dependency tree way is to use project report plugin.

  • Add project-report plugin in your build.gradle(module/app level) and sync
plugins {
    ...
    id 'project-report'
}
Enter fullscreen mode Exit fullscreen mode
  • In the terminal window, run the following command
gradlew htmlDependencyReport
Enter fullscreen mode Exit fullscreen mode
  • Open the .\app\build\reports\project\dependencies\index.xml
  • Search file debugRuntimeClasspath

The web-based output looks like this:
How_to_Show_Library_Dependencies_Tree_in_Android_Studio_07.JPG

Conclusion

Although the web-based dependency tree is user-friendly, method 2 - Command-line Dependency Tree is sufficient for me most of the time because it is quick!


Originally published at https://vtsen.hashnode.dev.

Latest comments (0)