能否在AAR包括传递依赖?AAR

2023-09-06 02:03:28 作者:你得宠着我

所以,现在我有一个库项目,比如项目依赖于一个库如 OkHttp

So, right now I have a Library project, say project Foo that depends on a library like OkHttp.

现在,在有行家buildstep产生的AAR并将其推到一个公共场所。

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

所以现在可以说我有项目B,我们把它叫做酒吧。酒吧是一个Android应用程序,而酒吧依赖于

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

嗯,我有。但是,当我提出从栏调用 OkHttp ,我得到这个消息:

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)

那么,这样的事可能吗?或将酒吧需要手工取决于 OkHttp 以及任何其他依赖有?

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

推荐答案

所以,过了好一会儿,但我发现我一直在寻找。这正好是我的样子我的文字搜索。

So, 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没有解决使用摇篮 AAR库的依赖

从本质上讲,我需要添加一个

Essentially, I needed to add a

transitive = true

到酒吧的build.gradle

to the build.gradle of Bar

例如:

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 'exclude' tag.