在android中创建一个带有依赖项的库 [英] Create a library with dependencies in android

查看:35
本文介绍了在android中创建一个带有依赖项的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个库LibA",它依赖于许多 3rd 方库,如 RecyclerView、EventBus 等.当我尝试将它作为 aar 包含在另一个项目中时,库已成功包含,但依赖项并未包含在 aar 中.

I created a library 'LibA' which has dependencies on many 3rd party libraries like RecyclerView, EventBus etc. When i tried to include it in another project as an aar, Library was included successfully but dependencies did not came in aar.

Q1 如何在 LibA 中包含依赖项,以便在其他项目包含此库时,不必担心我的库的内部依赖项.

Q1 How can I include dependencies in LibA, so that when some other project includes this library, it should not worry about internal dependencies of my library.

Q2 gradle 如何管理库的依赖项,是一次性下载所有依赖项,还是先检查主项目中已有的依赖项?

Q2 How does gradle manages dependencies of libraries, does it downloads all depenedencies at once, or first checks which are already available in the main project?

Q3 当有人从 jcenter 中包含一个库时,这是否会带来所有依赖项?

Q3 When someone includes a library from jcenter, does that brings all the dependencies with it?

任何帮助将不胜感激.:)

Any help will very much appreciated. :)

推荐答案

aar 文件不包含嵌套(或 transitive) 依赖 并且没有描述使用的依赖项的 pom 文件图书馆.

The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.

这意味着,如果您使用 flatDir 存储库导入 aar 文件,则还必须在项目中指定依赖项.

It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.

Q1 我如何在LibA中包含依赖,这样当其他项目包含这个库时,就不用担心我的库的内部依赖了.

Q1 How can I include dependencies in LibA, so that when some other project includes this library, it should not worry about internal dependencies of my library.

您应该使用 ma​​ven 存储库(您必须在私有或公共 Maven 存储库中发布库),您将不会遇到相同的问题.
在这种情况下,gradle 使用包含依赖项列表的 pom 文件下载依赖项.

You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.

Q2 gradle 如何管理库的依赖,是一次性下载所有依赖,还是先检查主项目中已经存在的依赖?

Q2 How does gradle manages dependencies of libraries, does it downloads all depenedencies at once, or first checks which are already available in the main project?

Gradle 为您处理依赖项.它不会两次或多次添加相同的依赖项.

Gradle handles the dependencies for you. It doesn't add the same dependency twice or more.

Q3 当有人包含来自 jcenter 的库时,是否会带来所有依赖项?

Q3 When someone includes a library from jcenter, does that brings all the dependencies with it?

如前所述,在这种情况下,依赖项有一个 pom 文件,它描述了所有嵌套的依赖项.Gradle 会自动下载它.

As said before, in this case the dependency has a pom file which describes all the nested dependencies. Gradle downloads it automatically.

这篇关于在android中创建一个带有依赖项的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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