在Android Library AAR中包含外部模块 [英] Include external module in Android Library aar

查看:726
本文介绍了在Android Library AAR中包含外部模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个足够简单的Android库build.gradle文件(删除了不相关的部分)

apply plugin: 'com.android.library'

repositories {
    maven { url 'https://dl.bintray.com/alexeydanilov/maven' }
}

dependencies {
    compile 'com.danikula:videocache:1.0.1'
}

我希望能够构建一个Android库.aar,其中包含我想要的所有文件,而且还包含来自videocache外部模块的所有文件.

我尝试了许多不同的技术来尝试实现这一目标(另一个项目,更改"transitive"的设置,尝试"export = true"),但都被证明不成功,我不确定我还能尝试什么.

如果我下载源.jar文件并将其放入libs中,则将必要的位添加到设置文件中,它正确地打包到了.aar中,但是我似乎找不到通过引用来完成此操作的任何方法这样的外部模块.

解决方案

首先,建议不要将外部lib包含到aar文件中.可以在此处:

我引用了以下内容:

使用人工制品将包括在人工耳中.整点 使用远程工件不是依靠jar,而是依靠 神器地址,以便使用您的"aar"的项目可以解决所有问题 其依赖关系图,查找重复项,解决冲突等...

如果您在Maven上发布"aar",则工件POM将包含 依赖关系.如果从多项目设置中使用它,则该项目 生成"aar"会将那些依赖项发送到项目 引用它.

对于本地jar,因为它们无法知道jar文件是什么 是我们必须将其打包在本地,但这实际上不是您所需要的 如果要将"aar"提交给工件回购,应使用

.

因此,如果要包括和使用远程仓库中的"aar"库,可以先发布它,然后将此行添加到依赖项中:

compile 'Replace with the link to your lib'

如果您想从本地使用'aar'文件,还有一种不太理想但可行的方法来包含所有外部库,只需复制以下行即可:

compile 'com.danikula:videocache:1.0.1'

依赖于正在使用您的lib的项目中的依赖项.但是无论如何,不​​建议这样做.

希望我的回答可以为您提供帮助.

I have a simple enough Android Library build.gradle file (irrelevant parts removed),

apply plugin: 'com.android.library'

repositories {
    maven { url 'https://dl.bintray.com/alexeydanilov/maven' }
}

dependencies {
    compile 'com.danikula:videocache:1.0.1'
}

And I would like to be able to build an Android Library .aar which has all the files I want in it, but also all the files which come down from the videocache external module.

I've tried many different techniques to try and achieve this (another project, changing settings of 'transitive', attempting 'export = true') but all have proven unsuccessful and I'm not sure what else I can try.

If I download the source .jar file drop it in to libs, add the necessary bits to the settings file, it packages into the .aar correctly, but I can't seem to find any way to do it via referencing the external module like this.

解决方案

First of all it is not recommended to include external lib into aar file. A previous answer for this can be found here:

I quoted the text as below:

Using an artifact will not include it in the aar. The whole point of using remote artifacts is to not rely on jars but instead on the artifact adress so that the project using your 'aar' can resolve all its dependency graph, find duplicates, resolve conflicts, etc...

If you publish your 'aar' on Maven, the artifact POM will contain the dependencies. If you use it from a multi-project setup, the project generating the 'aar' will send those dependencies to projects referencing it.

For local jars, because those are no ways of knowing what the jar file is we have to package it locally, but this is really not something you should use if you are going to submit the 'aar' to an artifact repo.

So if you want to include and use your 'aar' lib from remote repo, you can publish it first and then add this line to your dependencies:

compile 'Replace with the link to your lib'

If you want to use the 'aar' file from a local place, there is also a not so perfect but working way to include all the external libs, which is simply copy this line:

compile 'com.danikula:videocache:1.0.1'

to dependencies in the project which is using your lib. But anyhow this is not recommended.

Hope my answer can help you.

这篇关于在Android Library AAR中包含外部模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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