如何在Android库中包含依赖项? [英] How to include a dependency inside an Android library?

查看:96
本文介绍了如何在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
}

这篇关于如何在Android库中包含依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆