Create an AAR that depends on multiple AARs
I am working to build an SDK that can be used in other 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 work on, each one is a module in our system (infra, ui and protocol). Each one of them is creating an AAR.
Our SDK is a wrapper with some API calls to the lower layers.
We want to create one AAR that depends on all other AARs, but from some reason when we tried to run it, it says that he can't find the source code for some classes.
I found some questions related to this issue, but they didn't worked. Also tried to work with transitive
dependencies, but the bottom line is the same - can't find the source code.
transitive
dependencies. Is there anything else we can do?
From my answer here:
As far as I know you cannot include aars inside an aar. They don't have configuration files that state what dependencies they need. You can either
Strip the source code from the libraries you are using and compile it with your aar. This will do the job if the UI/Protocal/Infra libraries are in-house and you are the only provider.
Consider uploading to bintray or Maven Central Repository
Number two is more preferable since this way all your client has to do is to include a link such as compile 'com.abc.efg:version'
to grab all the dependencies you configured. It is also a much better option because there are ways of dealing with version conflicts (ex. with exclude group
).
Imagine if your client was using another sdk which was pulling in a different version of UI/Protocal/Infra. If your aar was given to them via 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 simply do
compile ('com.abc.efg:version') { exclude group: 'com.companyName.ui' }
and be free from all that headache. A real life example is Facebook's SDK. It pulls in google's play-services, but people often already include that as a dependency for their project and run into problems like this.
As your projects generally relies on both internal and third-party libraries. The internal libraries can be published on Artifactory repositories and resolve the dependencies over Artifactory with Gradle.
Its easy! Just go through the below articles,
This is highly scalable and its easy to maintain your code across multiple modules.
Hope this would help you!
链接地址: http://www.djcxy.com/p/92562.html上一篇: 如何从列表和地图数据中创建多个GenServer进程?
下一篇: 创建一个依赖多个AAR的AAR