gpt4 book ai didi

android - 在 Android 库 aar 中包含外部模块

转载 作者:太空狗 更新时间:2023-10-29 14:55:39 26 4
gpt4 key购买 nike

我有一个足够简单的 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 中正确,但我似乎无法通过像这样引用外部模块找到任何方法来做到这一点。

最佳答案

首先,不建议将外部库包含到aar 文件中。可以找到以前的答案 here :

我引用的文字如下:

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.

因此,如果您想从远程仓库中包含和使用您的“aar”库,您可以先发布它,然后将此行添加到您的依赖项中:

compile 'Replace with the link to your lib'

如果你想从本地使用 'aar' 文件,还有一种不那么完美但有效的方法来包含所有外部库,只需复制以下行:

compile 'com.danikula:videocache:1.0.1'

到正在使用您的库的项目中的依赖项。但无论如何,不​​推荐这样做。

希望我的回答能帮到你。

关于android - 在 Android 库 aar 中包含外部模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31792342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com