如何发布具有第三方依赖项的 android SDK? [英] How to release an android SDK with third party dependencies?

查看:70
本文介绍了如何发布具有第三方依赖项的 android SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个 Android SDK 来使用我们的 Restful API.我在我的 SDK 中使用了第三方库,如 Retrofit2 和 rxandroid.

I developed an android SDK to consume our restful API. I used third party libraries like retrofit2 and rxandroid in my SDK.

dependencies 
{
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
}

我向我的客户发布了一个 aar 文件.他的应用程序导入了我的 aar 文件并直接使用了我的服务,该服务由 Retrofit2 实现来使用 API.问题是他的应用程序还需要在他的依赖项部分包含retrofit2 和rxandroid 依赖项.有什么方法可以让我的客户直接使用我的服务而不在他的依赖项部分添加依赖项?因为我不希望我的客户知道我在我的 SDK 中使用了哪些库.

I released an aar file to my customer. His app imported my aar file and direct used my service which is implemented by retrofit2 to consume APIs. The problem is that his app also needs to include retrofit2 and rxandroid dependencies in his dependencies section. Is there any way letting my customer direct use my service without adding dependencies in his dependencies section? because I don't want my customer know which libraries I used in my SDK.

提前致谢.

推荐答案

据我所知,不能在 aar 中包含 aars.他们没有说明他们需要什么依赖项的配置文件.你可以

As far as I know you cannot include aars inside an aar. They don't have configuration files that state what dependencies they need. You can either

  1. 从你正在使用的库中剥离源代码并用你的 aar 编译它

  1. Strip the source code from the libraries you are using and compile it with your aar

考虑上传到 bintrayMaven 中央存储库

第二个更可取,因为这样您的所有客户端只需包含一个链接,例如 compile 'com.abc.efg:version' 即可获取所有依赖项.这也是一个更好的选择,因为有处理版本冲突的方法(例如使用 exclude group).

Number two is more preferable since this way all your client will only have to include a link such as compile 'com.abc.efg:version' to grab all the dependencies. It is also a much better option because there are ways of dealing with version conflicts (ex. with exclude group).

想象一下,如果您的客户正在使用另一个正在进行不同版本改造的 sdk.如果您的 aar 是通过第一种方法提供给他们的,由于版本冲突,他们甚至根本无法构建项目.但是对于第二个版本,他们可以简单地做

Imagine if your client was using another sdk which was pulling in a different version of retrofit. 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. However with the second version, they can simply do

compile ('com.abc.efg:version') { exclude group: 'com.squareup.retrofit2' }

并且免于所有的头痛.一个真实的例子是 Facebook 的 SDK.它引入了 google 的播放服务,但人们通常已经将其作为项目的依赖项包含在内,并遇到诸如 这个.

and be free from all that headache. A real life example is Facebook's 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.

这篇关于如何发布具有第三方依赖项的 android SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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