Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of dependencies runtime

Recently i was doing some research work on Android Dependencies and one question stuck on my mind. Question is can we get list of dependencies by using java code?

For example dependencies in my build.gradle file

dependencies {
   compile 'com.google.android.gms:play-services:+'
   compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}

Now if i want name of those dependencies while the app is running, can we get it?

like image 279
Ravi Avatar asked Jan 04 '16 12:01

Ravi


People also ask

How do I see dependencies in a jar file?

jar file. Use the -verbose:class option to find class-level dependencies or use the -v or -verbose option to include dependencies from the same JAR file. Use the -R or -recursive option to analyze the transitive dependencies of the com.

How do I list all Gradle dependencies?

If you want to visualize your dependencies in a graph you can use gradle-dependency-graph-generator plugin. Generally the output of this plugin can be found in build/reports/dependency-graph directory and it contains three files (. dot|. png|.


1 Answers

Not really. They are compile-time dependencies. In your compiled APK, there is no significant difference between:

  • compile 'com.facebook.android:facebook-android-sdk:4.1.0'

  • compile project(':facebook'), where you cloned a GitHub repo or something to give you a local library project as opposed to referencing an artifact from a repository

  • having a bunch of classes with Facebook's name and package in your app that you wrote (ditto a bunch of resources)

If you are writing the app, and you are using different build types and/or product flavors, and you have different dependencies for each, you can use BuildConfig to detect which build variant you are running.

If you are writing a library, and you want to determine at runtime if the developer added a certain dependency, the best you can do is sniff around to see if certain things exist from that dependency and if they match your expectations. The details for this will vary by dependency (e.g., seeing if Play Services exists would have one set of hard-coded checks; seeing if the Facebook SDK exists would have a separate set of hard-coded checks). This will not distinguish between my three bullets above, but it is the best that you are going to be able to do.

like image 102
CommonsWare Avatar answered Oct 12 '22 07:10

CommonsWare