简体   繁体   中英

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. :)

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.

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 some Dependency manager. For example Maven Central which has .pom file which defines all additional dependencies which should be used

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 downloads all necessary dependencies. It creates a graph for dependencies, try to solve conflicts and download them

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

If additional dependencies were not defined in pom file they will not be downloaded, only library

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM