简体   繁体   English

创建一个依赖于多个AAR的AAR

[英]Create an AAR that depends on multiple AARs

I am working to build an SDK that can be used in other application. 我正在努力构建一个可以在其他应用程序中使用的SDK。

My project structure is as follows: 我的项目结构如下:

ProjectFolder
  |
  +--AndroidLibs
  |      |
  |      +--UI (android library - AAR)
  |      |
  |      +--Protocol (android library - AAR)
  |      |
  |      +--infra (android library - AAR)
  |
  +--SDK(depends on UI, Protocol and Infra) 
  |
  +--APP(depends on SDK)

As you can see, we have 3 different libraries that we work on, each one is a module in our system (infra, ui and protocol). 如您所见,我们有3个不同的库,每个库都是我们系统中的模块(infra,ui和protocol)。 Each one of them is creating an AAR. 他们每个人都在创建一个AAR。

Our SDK is a wrapper with some API calls to the lower layers. 我们的SDK是一个包装器,包含对较低层的一些API调用。

We want to create one AAR that depends on all other AARs, but from some reason when we tried to run it, it says that he can't find the source code for some classes. 我们想要创建一个依赖于所有其他AAR的AAR,但是出于某种原因,当我们尝试运行它时,它说他找不到某些类的源代码。

I found some questions related to this issue, but they didn't worked. 我发现了一些与此问题相关的问题,但它们没有奏效。 Also tried to work with transitive dependencies, but the bottom line is the same - can't find the source code. 也尝试使用transitive依赖,但底线是相同的 - 找不到源代码。

  1. android-studio-how-to-package-single-aar-from-multiple-library-projects : One answer that says there no solution for that (Google employee). android-studio-how-to-package-one-aar-from-multi-library-projects :一个答案就是没有解决方案(Google员工)。
  2. create-an-aar-with-multiple-aars-jars : use the transitive dependencies. create-a-aar-with-multiple-aars-jars :使用transitive依赖。
  3. Create Mojo for creating AAR with all "aar" dependencies 创建Mojo以创建具有所有“aar”依赖关系的AAR

Is there anything else we can do? 我们还能做些什么吗?

From my answer here : 从我在这里的回答

As far as I know you cannot include aars inside an aar. 据我所知,你不能在aar里面包含aars。 They don't have configuration files that state what dependencies they need. 它们没有配置文件来说明它们需要哪些依赖项。 You can either 你也可以

  1. Strip the source code from the libraries you are using and compile it with your aar. 从您正在使用的库中删除源代码,然后用您的aar编译它。 This will do the job if the UI/Protocal/Infra libraries are in-house and you are the only provider. 如果UI / Protocal / Infra库是内部的,并且您是唯一的提供者,这将完成这项工作。

  2. Consider uploading to bintray or Maven Central Repository 考虑上传到bintrayMaven Central Repository

Number two is more preferable since this way all your client has to do is to include a link such as compile 'com.abc.efg:version' to grab all the dependencies you configured. 第二个是更优选的,因为这样你的客户端所要做的就是包含一个链接,比如compile 'com.abc.efg:version'来获取你配置的所有依赖项。 It is also a much better option because there are ways of dealing with version conflicts (ex. with exclude group ). 它也是一个更好的选择,因为有一些方法可以处理版本冲突(例如,使用exclude group )。

Imagine if your client was using another sdk which was pulling in a different version of UI/Protocal/Infra. 想象一下,如果你的客户正在使用另一个sdk,它正在拉入不同版本的UI / Protocal / Infra。 If your aar was given to them via the first method, they won't even be able to build the project at all due to version conflicts. 如果你的aar是通过第一种方法给他们的,那么由于版本冲突,他们甚至根本无法构建项目。 However with the second version, they can simply do 但是对于第二个版本,他们可以做到

compile ('com.abc.efg:version') { exclude group: 'com.companyName.ui' }

and be free from all that headache. 并摆脱所有头痛。 A real life example is Facebook's SDK. 一个真实的例子是Facebook的SDK。 It pulls in google's play-services, but people often already include that as a dependency for their project and run into problems like this . 它拉在谷歌的播放服务,但人们往往已经包含了它们作为其项目的依赖,并遇到类似问题,

As your projects generally relies on both internal and third-party libraries. 由于您的项目通常依赖于内部和第三方库。 The internal libraries can be published on Artifactory repositories and resolve the dependencies over Artifactory with Gradle. 内部库可以在Artifactory存储库上发布,并使用Gradle解决Artifactory上的依赖关系。

Its easy! 这很容易! Just go through the below articles, 请仔细阅读以下文章,

This is highly scalable and its easy to maintain your code across multiple modules. 这是高度可扩展的,并且易于跨多个模块维护代码。

Hope this would help you! 希望这会对你有所帮助!

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

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