Android Studio 外部库项目 [英] Android studio external library projects

查看:27
本文介绍了Android Studio 外部库项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 Eclipse 转移到 android studio,这是我在 Eclipse 中的设置:我有几个 Android 应用程序项目,依赖于一个工作区中的几个库项目(有些是共享的).在 Android Studio 中,我首先开始为每个应用程序创建一个项目,但很快意识到我必须将库项目作为使用它们的每个项目中的模块.这意味着复制库项目并将它们包含在每个应用程序中,这是高度冗余的,并且需要维护库的多个副本.

I'm moving from Eclipse to android studio and this is my set up in eclipse: I have several Android app projects, depending on several library projects (some shared) all within one workspace. In Android studio I first started creating a project per app, but quickly realized that I would have to have the library projects as modules within each project that uses them. This would mean duplicating the library projects and including them in each app, which is highly redundant and would require maintaining multiple copies of the libraries.

所以我改用我所有的应用程序和库作为同一个项目中的模块.这适用于构建,但会产生其他问题,例如版本控制问题,因为每个模块都位于单独的版本控制存储库中.

So I switched to having all my apps and libraries as modules within the same project. This works for building but creates other problems such as version control issues since each module lives in a separate version control repository.

进行此设置的最简洁方法是什么?真正的问题是,我可以在 AS 中拥有共享相同外部库项目的单独项目吗?

What is the cleanest way to have this setup? And the real question is, can I have separate projects in AS that share the same external library projects?

推荐答案

注意

随着 Android Studio 0.5.0 的发布,此答案已过时,但我将其保留在下方以供参考.有关更多最新说明,请参阅 如何跨多个项目共享单个库源

With the release of Android Studio 0.5.0, this answer is obsolete, but I'll leave it below for reference. For more up-to-date instructions, see How to share a single library source across multiple projects

在Android Studio中,很难有共享库项目,因为目前项目中的所有模块必须位于同一个根文件夹下是一个限制;当您尝试通过制作一个包含所有内容的大项目来解决问题时,您似乎发现了这一点.我们正在努力解除这一限制.

In Android Studio, it's difficult to have shared library projects, because currently it's a limitation that all modules in a project must live under the same root folder; it seems like you found this out when you tried to solve your problem by making one big project that includes everything. We're working on trying to lift this limitation.

现在最好的答案是让库模块分离项目并将它们发布到本地 Maven 存储库,并让依赖项目从该存储库中提取它们.不幸的是,这意味着您无法在单个项目的上下文中处理您的应用程序 + 库模块源.一个更大的缺点是这些库模块的源附件尚不可用,因此如果您尝试调试应用程序,您将难以进入库中的代码.

The best answer right now is to make the library modules separate projects and have them publish to a local Maven repository, and have the dependent projects pull them in from that repo. This means that you can't work on your app + library module sources from the context of a single project, unfortunately. A bigger disadvantage is that source attachments for those library modules doesn't work yet, so if you're trying to debug your app, you'll have difficulty stepping into code in the libraries.

我知道这不是一个很好的答案,但在 Android Studio 发展的这个阶段,它可能是我们能做的最好的.我们知道您的用例是一个相当普遍的用例,因此我们优先支持它.

I know this isn't a very great answer, but at this stage of Android Studio's evolution, it's probably the best we can do. We know yours is a fairly common use case, and it's a priority for us to support it.

这篇关于Android Studio 外部库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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