如何在Android库中包含依赖项?

如何在Android库中包含依赖项?

问题描述:

目前,我正在为需要Volley功能的android系统编写一个库.当前,在库的依赖关系块和任何使用该库的应用程序中都声明了Volley依赖关系.我该怎么做才能使我的库本身可以获取其所需的依赖关系,而不是让正在执行的应用程序也声明依赖关系?

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?

Gradle支持可传递依赖项.

Gradle supports transitive dependencies.

对于本地图书馆,其工作方式如下:

For a local library, this works like this:

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

对于远程库:

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