Create an AAR that depends on multiple AARs

I am working on creating an SDK that can be used in another application.

My project structure is as follows:

ProjectFolder | +--AndroidLibs | | | +--UI (android library - AAR) | | | +--Protocol (android library - AAR) | | | +--infra (android library - AAR) | +--SDK(depends on UI, Protocol and Infra) | +--APP(depends on SDK) 

As you can see, we have 3 different libraries that we are working on, each of which is a module in our system (infra, ui and protocol). Each of them creates an AAR.

Our SDK is a shell with some API calls for lower layers.

We want to create one AAR that depends on all the other AARs, but for some reason, when we tried to run it, it says that it cannot find the source code for some classes.

I found several questions related to this problem, but they did not work. I also tried to work with transitive dependencies, but the bottom line is the same - I cannot find the source code.

Is there anything else we can do?

+7
android module android-gradle gradle aar
source share
2 answers

From mine answer here :

As far as I know, you cannot include aars inside aar. They do not have configuration files that indicate the dependencies that they need. You can either

  • Separate the source code from the libraries you use and compile them with aar. This will be done if the UI / Protocal / Infra libraries are proprietary and you are the sole provider.

  • Consider uploading to bintray or Maven Central repository

Number two is preferable since all you have to do is include a link like compile 'com.abc.efg:version' to capture all the dependencies you configured. This is also a much better option, because there are ways to deal with version conflicts (for example, with an exclude group ).

Imagine that your client used a different sdk that pulled out a different version of UI / Protocal / Infra. If your aran was provided to them using the first method, they won’t even be able to build the project at all due to version conflicts. However, with the second version, they can just do

 compile ('com.abc.efg:version') { exclude group: 'com.companyName.ui' } 

and be free from all this headache. A real life example is the Facebook SDK. It attracts google gaming services, but people often already include this as a dependency on their project and run into problems like this .

+3
source share

How your projects usually use both internal and third-party libraries. Internal libraries can be published to Artifactory repositories and resolved dependencies on Artifactory using Gradle.

Easy! Just browse through the articles below,

It is very scalable and it is easy to maintain code on multiple modules.

Hope this helps you!

+1
source share

All Articles