166

My goal is to see the tree of dependencies (such as: appcompat, dagger, etc) in a particular project.

Like the one IntelliJ:

enter image description here

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
fruqi
  • 4,983
  • 4
  • 26
  • 32

9 Answers9

319

The image in the question doesn't really show a tree, just a flat list of everything compiled into the app.

Are you using Gradle?

If so, you can truly see the "tree" by running a Gradle command

Android documentation: View the dependency tree

GUI

  1. Select View > Tool Windows > Gradle (or click Gradle icon in the tool windows bar).
  2. Expand AppName > Tasks > android and double-click androidDependencies. After Gradle executes the task, the Run window should open to display the output.

CLI

(produces tree-like list)

./gradlew app:dependencies

and/or

(produces flat list)

./gradlew app:androidDependencies

Where app is your module's name

And you get something like so

+--- MyApp:mylibrary:unspecified
|    \--- com.android.support:appcompat-v7:25.3.1
|         +--- com.android.support:animated-vector-drawable:25.3.1
|         |    \--- com.android.support:support-vector-drawable:25.3.1
|         |         \--- com.android.support:support-v4:25.3.1
|         |              \--- LOCAL: internal_impl-25.3.1.jar
|         +--- com.android.support:support-v4:25.3.1
|         |    \--- LOCAL: internal_impl-25.3.1.jar
|         \--- com.android.support:support-vector-drawable:25.3.1
|              \--- com.android.support:support-v4:25.3.1
|                   \--- LOCAL: internal_impl-25.3.1.jar
\--- com.android.support:appcompat-v7:25.3.1
     +--- com.android.support:animated-vector-drawable:25.3.1
     |    \--- com.android.support:support-vector-drawable:25.3.1
     |         \--- com.android.support:support-v4:25.3.1
     |              \--- LOCAL: internal_impl-25.3.1.jar
     +--- com.android.support:support-v4:25.3.1
     |    \--- LOCAL: internal_impl-25.3.1.jar
     \--- com.android.support:support-vector-drawable:25.3.1
          \--- com.android.support:support-v4:25.3.1
               \--- LOCAL: internal_impl-25.3.1.jar

For specific flavor use the command

gradle app:dependencies --configuration <flavorNameRuntimeClasspath>

Note: If you run ls (or dir on Windows) in that folder, and don't see gradlew (or gradlew.bat), you are in the wrong folder.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Hey thanks for the answer, but I wanted to see from the IDE itself. So that I can browse the dependencies' code. – fruqi Aug 20 '16 at 00:27
  • You can run that from the IDE, there's a Gradle View on the right side of the IDE along the edge. You said dependency tree, so that's what I assumed you meant. This shows which dependencies are nested within each other and you can identify duplicates – OneCricketeer Aug 20 '16 at 13:30
  • 1
    Thanks, helped me a lot in tracking down some transient dependencies. – Mark Sep 02 '17 at 10:40
  • I think he meant "browse the dependencies code" like he wrote ;) Like it's possible in Eclipse (and maybe in IntelliJ IDEA), you can setup a breakpoint inside a dependency framework code. I guess the answer is it's just not possible in Android Studio. – Tristan Nov 28 '18 at 15:14
  • @Tristan Yes it is. I do it all the time – OneCricketeer Nov 28 '18 at 17:13
  • 4
    It's not what you are showing in this answer though, it's just a non interactive text list of dependencies – Tristan Nov 29 '18 at 07:50
  • @Tristan a "tree of dependencies" is exactly what is shown. The question did not ask for browsing source **code** of them. The question doesn't say code at all. If you search Maven or Gradle docs for "dependency tree", you get output like this – OneCricketeer Nov 29 '18 at 16:17
  • 1
    The question asked for a dependency tree "Like the one IntelliJ:" with a screen capture. Hard to be more explicit. And then he adds precision saying he wants to "browse the dependencies code". But your answer looks useful to some people anyway, just not the expected answer. – Tristan Nov 29 '18 at 17:35
  • 9
    This may be a newer gradle version thing, but the dependency tree seems to be displayed with `./gradlew appName:dependencies`. In Android Studio it can be found under `appName > Tasks > help > dependencies`. – omahena Jan 08 '19 at 14:19
  • @omahena Yes... Both of those are mentioned in the docs, and my answer. `dependencies` and `androidDependencies` are different, though – OneCricketeer Jan 08 '19 at 18:37
  • 3
    @cricket_007 I agree with you that the two tasks are different. And I may be holding it wrong... But I could not find a way to display a dependency tree with Gradle 4.6 and the `androidDependencies` task like the one in your answer. The results were just a flat list like the end result of a Gradle dependency search. Any idea why and how to get a tree like in your answer? – omahena Jan 11 '19 at 07:33
  • 1
    @omahena Well, I copied straight from the documentation. My answer used to say `app:dependencies` – OneCricketeer Jan 11 '19 at 07:34
  • Also, the [Android docs](https://developer.android.com/studio/build/dependencies#view-dependency-tree) are outdated. – Mokkun Feb 17 '19 at 13:09
  • @もっくん Again, it used to say that... And the docs used to say it as well, if I recall correctly.. And the bottom of that page does say *Last updated January 23, 2019.*, so... – OneCricketeer Feb 17 '19 at 19:43
  • Well, something is wrong then, since the output in your answer does not match what we see when running `./gradlew app:androidDependencies`. – Mokkun Feb 18 '19 at 08:10
  • @もっくん I think that output depends on **your** app. I copied what the docs say – OneCricketeer Feb 20 '19 at 22:53
  • 3
    Sorry, but I highly doubt that. If you create a new project with a "Basic Activity" on Android Studio, and you run the `./gradlew app:androidDependencies` task, the tree will be **flat** as oppose to what your answer describes. I understand you copied from the docs, but it won't be the first time they are wrong/outdated. – Mokkun Feb 21 '19 at 09:31
  • chmod +x gradlew on linux if you get permission denied msg – Arshdeep Singh Oct 17 '19 at 07:16
  • In Windows do not use `./` . In Mac or Linux it is usually required. – TeachMeJava Jan 15 '20 at 21:28
  • @TeachMeJava In Windows, use .\ , or use WSL – OneCricketeer Jan 15 '20 at 21:55
  • 1
    @mokkun I am also seeing flat output in AS Bumblebee Patch 2. – Code-Apprentice Mar 19 '22 at 01:08
  • this command is showing all the dependencies in straight line. Not in the heirarchy view – Bilal Bangash Oct 27 '22 at 15:35
  • I have no androidDependencies under Tasks. Only see build and run tasks. – steve Jun 28 '23 at 14:52
  • This answer is 7+ years old. Feel free to suggest an edit. – OneCricketeer Jun 28 '23 at 19:09
31

On the right side, open the gradle tab > click the gradle icon (execute gradle task), in the popup dialog enter :

app:dependencies

in the command line field > ok

Jamal S
  • 1,649
  • 1
  • 19
  • 24
  • 2
    This worked for me once I removed `app:` and just executed `dependencies`. This gives more useful output than the method in norbDEV's answer as it shows a dependency tree. Possibly the same output as `./gradlew dependencies` but without the requirement of installing a JDK. – jk7 Oct 02 '18 at 15:29
  • 1
    @jk7 `app` is the default module for Android Studio projects. If you have no modules, or want to see dependencies for all modules, yes, `gradle dependencies` also works – OneCricketeer Nov 17 '18 at 03:20
  • How to find dependencies of a specific flavor? – M. Usman Khan May 05 '21 at 18:16
  • 1
    @M.UsmanKhan check https://stackoverflow.com/a/63137778/2641657 – Jamal S May 06 '21 at 07:28
  • Definitely the best and fastest answer ! – Jonathan POIRIER Sep 24 '22 at 10:05
26

Android Studio 3.4

Inspect and visualize each dependency in the dependency graph of your project, as resolved by Gradle during project sync, by following these steps:

  1. Android Studio -> File -> Project Structure (Dialog)
  2. In the left pane of the "Project Structure" window, select Dependencies.
  3. In the Modules pane, select a module for which you’d like to inspect the resolved dependencies.

Project Structure

  1. For Android Studio 3.6 and above: On the right side of the "Project Structure" window, look at the Resolved Dependencies pane. An example is shown below, where you can click on the Expand arrows to navigate into each sub-dependency. However, it does not allow text searching, like the console output does.

Resolved Dependencies Pane

Learn more.

Mr-IDE
  • 7,051
  • 1
  • 53
  • 59
Anor
  • 1,110
  • 13
  • 14
  • this is almost what we want. too bad, it neither supports search nor opening/browsing them from here. – Ace Aug 22 '21 at 12:03
  • 3
    Actually you can also search .. just click somewhere within resolved dependencies and start typing. However I'm facing performance issues – Tima Feb 15 '22 at 08:35
  • This helped me get there. But in AS Bumblebee Patch 2, the central pane is flat, not a tree. You have to expand the Target Mdules/Artifacts on the right to see parent dependencies of a selected dependency. There's a possibility that I see different output due to using custom flavors in my build. – Code-Apprentice Mar 19 '22 at 01:10
22

Android Studio 3.+

  • Open the Gradle panel
  • Click the elephant icon, which has the tooltip "Execute Gradle Task"

Gradle panel screenshot + elephant icon

  • Select the app gradle project
  • In the command line paste: dependencies
  • Click OK

Screenshot: Run Gradle Task - Window

In the Run panel you will find the dependency tree.


Another method:

  • Open the Gradle panel

  • Find the "(root)" postfix and open (app's folder name)

  • Open the Tasks node

  • Open the android node

  • Double click on the "androidDependencies"

In the Run panel you will find the dependency list

Before a normal build switch back to the normal Build Configuration (next to the hammer)


Another useful tool:

How to find what dependency is updated: https://github.com/ben-manes/gradle-versions-plugin

Usage

  • Add this to project level build.gradle

    apply plugin: "com.github.ben-manes.versions"
    
    buildscript {
      repositories {
        jcenter()    
      }
    
      dependencies {
        classpath "com.github.ben-manes:gradle-versions-plugin:0.20.0"
      }
    }
    
  • Sync Now

  • Open the Gradle panel
  • Click the elephant icon
  • Select the root project
  • In the command line paste: dependencyUpdates
  • Click OK
  • Wait a little bit

In the Run panel you will find the result.

Mr-IDE
  • 7,051
  • 1
  • 53
  • 59
norbDEV
  • 4,795
  • 2
  • 37
  • 28
  • 1
    This creates a flat list of dependencies rather than a tree, so not as useful if you need to figure out which library is using a particular dependency. +1 for the "switch back to the normal build configuration" tip. – jk7 Oct 02 '18 at 15:49
15

Finally, I figured it out. What I do is to select Project from Project menu (See the image below).

enter image description here

fruqi
  • 4,983
  • 4
  • 26
  • 32
  • 16
    This is in no way a dependency _tree_. Dependency trees are used e.g. to find conflicting versions when library A uses library B version 1 while library C uses library B version 2. As the question stands, this answer is not correct. The question should be updated to request a list of used libraries, or cricket_007's answer should be the accepted one. – JHH Jun 21 '18 at 10:20
10

In latest android studio canary version you have dependency analyzer in Gradle tool

enter image description here

Zoran
  • 1,502
  • 19
  • 22
7

terminal command to see all dependencies list is

 ./gradlew -q dependencies app:dependencies --configuration implementation
vikas kumar
  • 10,447
  • 2
  • 46
  • 52
7

Click the Gradle tab and go to AppName > Tasks > help > dependencies

Android studio dependencies

Wirling
  • 4,810
  • 3
  • 48
  • 78
0

Simple use is to type text to Terminal or PowerShell:

./gradlew app:dependencies

Advanced usage:

./gradlew app:dependencies --configuration implementation
./gradlew app:dependencies --configuration testImplementation
./gradlew app:dependencies --configuration androidTestImplementation
Eugene Babich
  • 1,271
  • 15
  • 25