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?
Add your AAR or JAR as a dependency To use your Android library's code in another app module, proceed as follows: Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Jar Dependency in the dropdown.
Android Archive (AAR) plug-ins are bundles that include compiled Java and native (C/C++) code, resources, and an Android Manifest. The . aar file itself is a zip archive which contains all of the Assets. For more details, see Android Developer documentation on creating an Android Library.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With