AAR 可以包含传递依赖吗? [英] Can an AAR include transitive dependencies?

查看:59
本文介绍了AAR 可以包含传递依赖吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有一个库项目,比如说项目 Foo,它依赖于像 OkHttp 这样的库.

Right now I have a library project, say project Foo that depends on a library like OkHttp.

现在,Foo 有一个 Maven 构建步骤,可以生成 AAR 并将其推送到公共场所.

Now, Foo has a Maven buildstep that generates an AAR and pushes it up to a public place.

现在假设我有项目 B,我们将其命名为 Bar.Bar 是 Android 应用,Bar 依赖于 Foo.

Now lets say I have project B, we'll call it Bar. Bar is an Android application, and Bar depends on Foo.

嗯,我有.但是,当我从调用 OkHttp 的 Bar 调用 Foo 中的 public static 函数时,我收到以下消息:

Well, I have that. However, when I make a call to a public static function in Foo from Bar that calls OkHttp, I get this message:

java.lang.NoClassDefFoundError: com.squareup.okhttp.OkUrlFactory
            at com.foo.sdk.utils.OkHttpStack.<init>(OkHttpStack.java:15)

这种事情可能吗?或者 Bar 是否需要手动依赖 OkHttp 以及 Foo 的任何其他依赖项?

Is such a thing possible? Or will Bar need to manually depend on OkHttp as well as any other dependencies Foo has?

推荐答案

花了一点时间,但我找到了我想要的东西.这恰好是我表达搜索的方式.

It took a little while but I found what I was looking for. It just happened to be the way I was wording my searches.

这个鲜为人知的答案正是我想要的:

This lesser-seen answer was exactly what I was looking for:

使用 gradle 的 aar 库没有解析传递依赖

请注意,首先,如果 aar 库托管在 maven 存储库中,则依赖项仅与 aar 库相关联,因为 pom 文件不包含在 aar 中.

Note that dependencies are only associated with aar libraries if they are hosted in a maven repository, in the first place, as the pom file is not included in the aar.

基本上,我需要添加一个

Essentially, I needed to add a

transitive = true

...到Bar的build.gradle

示例:

compile ('com.foo:FOO:1.0.0@aar'){
       transitive=true
}

这样它就包含了我所有的传递库.

This way it includes all of my transitive libraries.

但是请注意,这实际上可能会导致依赖项(尤其是本地依赖项)之间的冲突,可以使用 exclude 标记解决这些冲突.

Note, however, that this may actually cause conflicts between dependencies (especially local ones) which can be resolved using an exclude tag.

这篇关于AAR 可以包含传递依赖吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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