Android AAR 可以包含传递依赖吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25698160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:39:18  来源:igfitidea点击:

Can an AAR include transitive dependencies?

androidmavengradleandroid-studioandroid-gradle-plugin

提问by VicVu

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

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

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

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

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

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

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

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

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

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

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

采纳答案by VicVu

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:

这个鲜为人知的答案正是我正在寻找的:

Transitive dependencies not resolved for aar library using gradle

使用 gradle 无法为 aar 库解析传递依赖项

Essentially, I needed to add a

本质上,我需要添加一个

transitive = true

...to the build.gradleof Bar

...到build.gradle酒吧

Example:

例子:

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

This way it includes all of my transitive libraries.

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

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

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