Can gradle only allow dependencies from an Android.aar file?

I am working on an internal library (name it "banana_lib"), which will be included in the Android application project. I want to provide this library to the client as an .aar file.

My library depends on another library (say Gson). If I can do this, I want to avoid combining the classes of this dependency into my library (the “thick jar”, ​​“uber jar” approach).

I know that I can ask a user of my library to include dependencies in the build.gradle file of the application:

dependencies { compile 'com.google.code.gson:gson:2.2.4' compile files('libs/banana_lib.aar') 

}

But I don’t want to burden the library user with including the dependencies of my library in the build.gradle file of the application.

Question: Is there a way to make gradle automatically resolve / enable dependencies of a .aar file? How can this be done so that the user of the .aar library has minimal effort? Do I need to provide a couple of .aar and .pom files? My main goal here would be to reduce what the user of this library should do. I feel that the library should ideally define all its dependencies, and gradle should just allow them in the background.

Put it a little differently: is there a way to allow the client / user to include the (internal!) Library (which has external dependencies): 1.) add the .aar file to the assembly. 2.) including it in build.gradle.

If there are other solutions that save the amount of work that the user / switch of the library should do with a minimum, then this would be interesting as well :)

Thank you very much!

+6
source share
1 answer

But I don’t want to burden the library user with including the dependencies of my library in the build.gradle file of the application.

Then publish the AAR and POM to the artifact repository, where POM defines the dependencies.

I feel that the library should ideally identify all the dependencies, and gradle should just allow them in the background.

This is not how JAR and AAR work. There is also no dependency information in the JAR or AAR. Both rely on POM or other external dependency information declarations, version information, etc.

Is there a way to allow the client / user to include the (internal!) Library (which has external dependencies): 1.) adding the .aar file to the assembly. 2.) including it in build.gradle.

Publish AAR and POM to the artifact repository, where POM defines the dependencies.

Note that “artifact storage” does not necessarily imply Maven Central or JCenter. The artifact repository can only be a directory tree, especially when accessed through the local file system. 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 the repository to be hosted on a website (for example, on an internal web server), this is possible, although you need to add index.html files in a directory style at each level of the directory tree. Or, Sonatype and Bintray sell specialized artifact repository servers, as I understand it.

+5
source

All Articles