简体   繁体   English

在Android库中包含外部模块aar

[英]Include external module in Android Library aar

I have a simple enough Android Library build.gradle file (irrelevant parts removed), 我有一个简单的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'
}

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. 我希望能够构建一个Android库.aar ,它包含我想要的所有文件,还包括从videocache外部模块下载的所有文件。

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. 我尝试了很多不同的技术来实现这个目标(另一个项目,更改'传递'的设置,尝试'export = true')但是所有这些都被证明是不成功的,我不确定我还能尝试什么。

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. 如果我下载源.jar文件将其放入libs,将必要的位添加到设置文件中,它正确打包到.aar ,但我似乎无法通过引用外部模块找到任何方法这个。

First of all it is not recommended to include external lib into aar file. 首先,不建议将外部lib包含在aar文件中。 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. 使用神器不会将其包含在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... 使用远程工件的重点是不依赖于jar而是依赖于工件地址,以便使用“aar”的项目可以解析其所有依赖关系图,查找重复项,解决冲突等...

If you publish your 'aar' on Maven, the artifact POM will contain the dependencies. 如果您在Maven上发布'aar',则工件POM将包含依赖项。 If you use it from a multi-project setup, the project generating the 'aar' will send those dependencies to projects referencing it. 如果您在多项目设置中使用它,生成'aar'的项目会将这些依赖项发送到引用它的项目。

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. 对于本地jar,因为那些无法知道jar文件是什么,我们必须在本地打包它,但如果你要将'aar'提交给工件仓库,那么这不是你应该使用的东西。

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: 因此,如果要包含并使用来自远程仓库的“aar”库,可以先将其发布,然后将此行添加到依赖项中:

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: 如果你想使用来自本地的'aar'文件,那么还有一个不太完美但工作的方式来包含所有外部库,这只是复制这一行:

compile 'com.danikula:videocache:1.0.1'

to dependencies in the project which is using your lib. 使用lib的项目中的依赖项。 But anyhow this is not recommended. 但无论如何这不推荐。

Hope my answer can help you. 希望我的回答可以帮到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM