I'm working on a internal library (let's call it "banana_lib") that will be included in an Android app project. I want to provide this library to a client in the form of an .aar file.
My library depends on another library (let's say Gson). If I can help it, I want to avoid bundling the classes of this dependency into my library ( the "fat jar", "uber jar" approach ).
I know that I could ask the user of my library to include the dependencies in the build.gradle file of the app:
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/banana_lib.aar')
}
But I don't want to burden the user of the library with including the dependencies of my library in the build.gradle file of the app.
Question: Is there a way to make gradle automatically resolve/include the dependencies of an .aar file? What's the way to do this so that a user of a .aar library has the minimum effort? Do I need to provide a pair of .aar and .pom file? My main goal here would be to reduce the things that a user of this library would have to do. I feel like a library should ideally define all its dependencies, and gradle should just resolve them in the background.
Put in a slightly different way: Is there any way to allow a client/user to include a (internal!)library(which has external dependencies) by just: 1.) adding a .aar file to the build. 2.) including it in the build.gradle.
If there are other solutions that keep the amount of work that the user/includer of the library has to do to a minimum, then that'd be interesting as well :)
Many thanks!
But I don't want to burden the user of the library with including the dependencies of my library in the build.gradle file of the app.
Then publish the AAR and a POM in an artifact repository, where the POM spells out the dependencies.
I feel like a library should ideally define all it's dependencies, and gradle should just resolve them in the background.
That is not how JARs and AARs work. Neither have dependency information in the JAR or AAR. Both rely on POMs or other external declarations of dependency information, versioning information, etc.
Is there any way to allow a client/user to include a (internal!)library(which has external dependencies) by just: 1.) adding a .aar file to the build. 2.) including it in the build.gradle.
Publish the AAR and a POM in an artifact repository, where the POM spells out the dependencies.
Note that "an artifact repository" does not necessarily imply Maven Central or JCenter. An artifact repository can be just a directory tree, particularly when accessed via a local filesystem. For example, you already have two of these local repositories on your development machine, most likely: the Android Repository and the Google Repository. If you want to have the repository hosted on a Web site (e.g., internal Web server), that's possible, though you need to add directory-style index.html
files at each level of the directory tree. Or, Sonatype and Bintray sell dedicated artifact repository servers, as I understand it.
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