How to include a dependency inside an Android libr

2019-06-07 02:26发布

问题:

Currently i'm writing a library for android that needs Volley to function. Currently, the Volley dependency is declared in both the dependencies block for the library and whatever app uses the library. What do I need to do so that my Library can pull in its needed dependencies itself, instead of having the implementing app also declaring the dependency?

回答1:

Gradle supports transitive dependencies.

For a local library, this works like this:

compile(project(:LIBRARY_NAME)) {
    transitive=true
}

For remote libraries:

compile ('com.somepackage:LIBRARY_NAME:1.0.0'){
    transitive=true //default, normally no need to specify explicitly
}