Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a library with dependencies in android

I created a library 'LibA' which has dependencies on many 3rd party libraries like RecyclerView, EventBus etc. When i tried to include it in another project as an aar, Library was included successfully but dependencies did not came in aar.

Q1 How can I include dependencies in LibA, so that when some other project includes this library, it should not worry about internal dependencies of my library.

Q2 How does gradle manages dependencies of libraries, does it downloads all depenedencies at once, or first checks which are already available in the main project?

Q3 When someone includes a library from jcenter, does that brings all the dependencies with it?

Any help will very much appreciated. :)

like image 543
Dave Ranjan Avatar asked May 06 '16 07:05

Dave Ranjan


People also ask

How do I add library dependencies?

To add a dependency on a library that is an annotation processor, you must add it to the annotation processor classpath using the annotationProcessor configuration. That's because using this configuration improves build performance by separating the compile classpath from the annotation processor classpath.

What is dependency library?

Dependency on libraries. If a module or mediation module needs to use resources from a library or if a library needs to use resources from another library, you have to open the module or library with the dependency editor and add a dependency on the required library.


1 Answers

The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.

It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.

Q1 How can I include dependencies in LibA, so that when some other project includes this library, it should not worry about internal dependencies of my library.

You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.

Q2 How does gradle manages dependencies of libraries, does it downloads all depenedencies at once, or first checks which are already available in the main project?

Gradle handles the dependencies for you. It doesn't add the same dependency twice or more.

Q3 When someone includes a library from jcenter, does that brings all the dependencies with it?

As said before, in this case the dependency has a pom file which describes all the nested dependencies. Gradle downloads it automatically.

like image 186
Gabriele Mariotti Avatar answered Oct 20 '22 23:10

Gabriele Mariotti