共享使用摇篮多个Android应用程序之间的一个Android库 [英] Sharing an Android library between multiple Android apps using Gradle

查看:152
本文介绍了共享使用摇篮多个Android应用程序之间的一个Android库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Andr​​oid应用程序A和B.我想提取每个重复code到共享库L.我怎样才能做到这一点使用摇篮?我已经看到这个问题之前问了几个排列,但也有极少数的答案。

I have Android apps A and B. I want to extract duplicate code from each into a shared library L. How can I do this using Gradle? I've seen a few permutations of this question asked before, but there were very few answers.

最接近/最佳业已问的问题是这个:

The closest/best already-asked question is this one:

<一个href="http://stackoverflow.com/questions/19937234/multiple-android-apps-depending-on-android-library-with-gradle">Multiple根据与摇篮的Andr​​oid库的Andr​​oid应用程序

Multiple Android apps depending on android library with gradle

第一个答案提出了一个父项目,既包括应用程序和库模块。这种耦合是不可取的,部分原因是A,B和L分别在自己的Git仓库,而且还因为它会涉及有一个父项目,并建立档案,这将是很难把源代码控制(或会涉及的手动复制其他项目)。由于Android的工作室默认情况下,喜欢一个父生成单模块项目...那么,它只是很多家长为了什么应该是一个简单的家庭。这真的好像在其他方面完全不相关的项目之间的不必要的耦合。

The first answer suggests a parent project that encompasses both apps and the library module. This coupling is undesirable, in part because A, B, and L are in their own Git repository, but also because it would involve having a parent project and build files that would be difficult to put in source control (or would involve manual copying of the other projects). Since Android Studio likes a parent build for single-module projects by default...Well, it's just a lot of parents for what should be a simple family. It really seems like an unecessary coupling between projects that are otherwise completely unrelated.

第二个答案涉及释放的AAR到回购和引用在每个项目中的远程库。我会被罚款这种方法,因为我们有一个本地的Nexus库,但似乎没有成为一个简单的方法来做到这一点,而无需手动版本/命名和上传文件(这是不可持续的)。我试图使用Sonatype的摇篮释放插件,但它似乎是JAR文件(未AARS)。

The second answer involves releasing an AAR to a repo and referencing the remote library in each project. I would be fine with this approach as we have a local Nexus repository, but there does not seem to be a simple way to do this without manually versioning/naming and uploading files (this is unsustainable). I'm trying to use the Sonatype gradle-release plugin, but it seems to be for JARs (not AARs).

这似乎只是像很多运动部件的数额是多少,Android的应用程序之间code共享最基本的形式。任何人都不会有一个更好的解决方案?

It just seems like a lot of moving parts for what amounts to the most basic form of code sharing between Android apps. Does anyone have a better solution?

推荐答案

您最好的选择是去AAR的路线,并将其发布到Maven 的http://www.vandalsoftware.com/post/52468430435/publishing-an-android-library-aar-to-a-maven

Your best bet is to go the aar route and publish it to maven http://www.vandalsoftware.com/post/52468430435/publishing-an-android-library-aar-to-a-maven

这篇关于共享使用摇篮多个Android应用程序之间的一个Android库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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