0

When I have an aar library how to list all the dependencies of this aar ? for exemple i have facebook-core-5.15.1.aar and the dependencies are :

+--- com.facebook.android:facebook-core:5.15.1
|    +--- com.parse.bolts:bolts-android:1.4.0
|    |    +--- com.parse.bolts:bolts-tasks:1.4.0
|    |    \--- com.parse.bolts:bolts-applinks:1.4.0
|    |         \--- com.parse.bolts:bolts-tasks:1.4.0
|    +--- com.android.support:support-annotations:27.0.2
|    +--- com.android.support:support-core-utils:27.0.2
|    |    +--- com.android.support:support-annotations:27.0.2
|    |    \--- com.android.support:support-compat:27.0.2
|    |         +--- com.android.support:support-annotations:27.0.2
|    |         \--- android.arch.lifecycle:runtime:1.0.3
|    |              +--- android.arch.lifecycle:common:1.0.3
|    |              \--- android.arch.core:common:1.0.0
|    \--- com.android.installreferrer:installreferrer:1.1

How to retrieve this dependencies tree from a command line? and accessory how to know where to download all thoses dependencies?

I need to know this because as far as I know If I add com.facebook.android:facebook-core:5.15.1.aar in my project without adding com.parse.bolts:bolts-android:1.4.0.aar (for exemple), then my project will not work.

In the research I did I found this way to know all the dependencies needed by a libraries, I must create a android studio project, add the dependencies like this:

dependencies {
    implementation 'com.facebook.android:facebook-core:5.15.1'
}

and then run: gradlew app:dependencies But I want to avoid to create an android project and I need to automate the task from a command line

zeus
  • 12,173
  • 9
  • 63
  • 184
  • 1
    During your research phase prior to asking this question, did you see the following existing questions?: [1](https://stackoverflow.com/q/42855351/20170164), [2](https://stackoverflow.com/q/48408209/20170164), [3](https://stackoverflow.com/q/37315094/20170164), [4](https://stackoverflow.com/q/50301536/20170164)? You should show that you did your research by explaining how your question is different than them, or why you decided to ask a new one instead of bountying the existing ones. – rainbow.gekota Oct 25 '22 at 21:52
  • Concerning the first three Qs I linked above, I can understand why you'd ask a new question, but the fourth is probably enough to merit not asking a new question- or at least asking and then self-answering, since the only added value seems to be the part about doing it via command-line. Finding [this _question_](https://stackoverflow.com/q/49006280/20170164) also should have been able to answer your question (not a duplicate, since the _question_ itself is what could/would answer your question). – rainbow.gekota Oct 25 '22 at 21:57
  • _Your second_ question about how to download those dependencies could/should(?) probably be a separate question post. If you want to save this question post and preserve its value for posterity, I'd recommend moving the part about downloading those dependencies to a separate question- lest this post get closed for lacking focus once the bounty period ends. – rainbow.gekota Oct 25 '22 at 21:58
  • Also, your question is confusing in that you show what looks like the output of running the `androidDependencies` gradle task, but don't specify what action you took to get that output, or why that action was insufficient compared to what you are looking for. Please [edit] to clarify. I'm assuming you got it from doing an action in an IDE. You should also specify whether you care if a command given in an answer outputs other information than that which you are interested in. Ie. Is it okay if the command prints the dependency tree of other aar libraries too? – rainbow.gekota Oct 25 '22 at 22:13
  • @rainbow.gekota I simply didn't find those questions. anyway their is no answer in them ans i prefer to reformulate the question in a different way. The 4th question is not an answer to my question because it's not from the command line. what is the mechanism used by tool like android studio to know the dependencies of an aar? – zeus Oct 26 '22 at 05:35
  • @rainbow.gekota I edited the question with the results of the research I did – zeus Oct 26 '22 at 05:39
  • @zeus you can only get dependencies of project, if you want to list dependencies of library, go directly to see its `build.gradle` source (from github, gitlab...). – NamNH Oct 26 '22 at 06:30
  • @NamNH so how android studio does to retrieve the list of dependencies of a library ? – zeus Oct 26 '22 at 06:42
  • 1
    For `com.facebook.android:facebook-core:5.15.1`, the (direct) dependencies can be found [here](https://repo1.maven.org/maven2/com/facebook/android/facebook-core/5.15.1/facebook-core-5.15.1.pom). Then you iterate to find the transitive dependencies. – Olivier Oct 26 '22 at 07:43
  • @Olivier look like a potential wining answer, but how to contruct this url for all aar? for exemple for com.google.firebase:firebase-messaging:12.0.1 I tried https://repo1.maven.org/maven2/com/google/firebase/firebase-messaging/12.0.1/firebase-messaging-12.0.1.pom but not found :( – zeus Oct 26 '22 at 10:45
  • Android artifacts are hosted on Google's own repository (maven.google.com), so the URL is [this](https://maven.google.com/com/google/firebase/firebase-messaging/12.0.1/firebase-messaging-12.0.1.pom). – Olivier Oct 28 '22 at 07:27
  • maybe this link help you : https://gist.github.com/n-belokopytov/d44949590748b096c1a497008b761d04 – Majid Arabi Oct 29 '22 at 14:18
  • @Olivier please answer you remaks, it's the wining answer : use POM to detect the dependencies – zeus Oct 31 '22 at 12:18

4 Answers4

1

AFAIK, when you run ./gradlew app:dependencies command, it will report all dependencies of the app module, no command for specific library's dependencies report. However, Android Studio have the resolved dependencies report (after synced project), you may check if it is your need.

File > Project Structure > Dependencies menu > Your modules (app) > Resolved dependencies.

enter image description here

NamNH
  • 1,752
  • 1
  • 15
  • 37
  • thanks @namNH, Yes but I need to automate the task from a command line and I can't use a GUI. answer of Olivier look a good starting point but I can't make it working – zeus Oct 26 '22 at 10:48
0

List of dependencies can be found on mvnrepository.com or search.maven.org

You can write a program that will parse these sites and give out data in the desired format

P.S. Resolving child dependencies is one of the main purposes of gradle. The fact that you have to manually write child dependencies indicates that you have some kind of error in the configuration (maybe a newer version of the dependency is already included)

Nick
  • 3,691
  • 18
  • 36
0

You might be looking for something already existing, for example: https://github.com/status-im/go-maven-resolver. Usage:

$ echo commons-io:commons-io:2.4 | ./go-maven-resolver
https://repo.maven.apache.org/maven2/commons-io/commons-io/2.4/commons-io-2.4.pom
https://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/25/commons-parent-25.pom
https://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.pom

Although it gives you dependency URLs, but you can easily parse them to get GAV coordinates, or modify the script to print out the tree-like structure.

romtsn
  • 11,704
  • 2
  • 31
  • 49
0

A library (aar or jar) does not contain any dependency informations by itself. However, libraries are generally available in Maven repositories, and such repositories provide dependency informations via POM files (which are XML files).

The URL where a POM file is available can be constructed from the following elements:

  • Repository URL
  • groupId
  • artifactId
  • version

The main repository is Maven Central. Its URL is https://repo1.maven.org/maven2/. Most libraries are available there.

For com.facebook.android:facebook-core:5.15.1, the POM URL is:

https://repo1.maven.org/maven2/com/facebook/android/facebook-core/5.15.1/facebook-core-5.15.1.pom

The file contains a <dependencies> element:

<dependencies>
    <dependency>
      <groupId>com.parse.bolts</groupId>
      <artifactId>bolts-android</artifactId>
      <version>1.4.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-annotations</artifactId>
      <version>27.0.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-core-utils</artifactId>
      <version>27.0.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.android.installreferrer</groupId>
      <artifactId>installreferrer</artifactId>
      <version>1.1</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

Only the direct dependencies are listed. To get the so-called "transitive dependencies", you need to iterate the process and fetch the POM files of the dependencies.

Note that Google publishes its Android libraries in its own Maven repository, at this URL:

https://maven.google.com/

So, for com.google.firebase:firebase-messaging:12.0.1, the POM URL is:

https://maven.google.com/com/google/firebase/firebase-messaging/12.0.1/firebase-messaging-12.0.1.pom

Olivier
  • 13,283
  • 1
  • 8
  • 24