使用Android Studio和gradle这个时候是否有可能项目之间共享库项目? [英] Is it possible to share library projects between projects when using Android Studio and gradle?

查看:120
本文介绍了使用Android Studio和gradle这个时候是否有可能项目之间共享库项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我竭力要弄清楚如何导入库项目进入Android的工作室在一个时尚,使它们可用于多个项目。新构建系统的文档意味着你需要导入库项目到您正在从事的项目的根目录:

I'm struggling to figure out how to import library projects into Android Studio in a fashion that makes them available to multiple projects. The documentation for the new build system implies that you need to import library projects into the root of the project you are working on:

摇篮项目也可以通过使用多项目的设置依赖于其它的gradle项目。多项目的设置通常的工作原理是让所有的项目,给定根工程的子文件
  (的http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup)

Gradle projects can also depend on other gradle projects by using a multi-project setup. A multi-project setup usually works by having all the projects as sub folders of a given root project (http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup)

这是因为有问题的,正如我上面提到的,我想保持经常使用的库访问所有当前和未来的项目。例如,目前我正在试图凌空集成到一个新的项目,以评估它,与我会想在将来使用它在多个其他项目的假设。我把它克隆到我的$ {} PROJECT_ROOT /文件夹,这是我创造了我的测试项目相同的水平,给我:

This is problematic since, as I mentioned above, I would like to keep frequently-used libraries accessible to all current and future projects. For example, I am currently trying to integrate Volley into a new project to evaluate it, with the assumption that I will want to use it in multiple other projects in the future. I cloned it to my "${PROJECT_ROOT}/" folder, which is the same level at which I created my test project, giving me:

$ {} PROJECT_ROOT / TestProject /测试

$ {} PROJECT_ROOT /抽射

${PROJECT_ROOT}/TestProject/Test
${PROJECT_ROOT}/volley

试图建立我的项目的build.gradle文件中以各种方式后,我已经成功地使应用程序编译的唯一方法是凌空迁入TestProject主项目,给我:

After trying to set up my project's build.gradle file in a variety of ways, the only way that I've managed to make the app compile is to move Volley into the TestProject 'main' project, giving me:

$ {} PROJECT_ROOT / TestProject /测试

$ {} PROJECT_ROOT / TestProject /抽射

${PROJECT_ROOT}/TestProject/Test
${PROJECT_ROOT}/TestProject/volley

这不仅prevent我在不在TestProject的一部分,而无需复制它或克隆它第二次其他项目使用凌空,但它意味着混帐要我把它添加到回购我在已经的TestProject根成立。

Not only does this prevent me from using Volley in other projects that are not a part of TestProject without duplicating it or cloning it a second time, but it means that git wants me to add it to the repo I've established at the root of TestProject.

我怎么可以参考库项目在我的Andr​​oid Studio项目,而不包括他们在项目本身?

How can I reference library projects in my Android Studio projects without including them in the projects themselves?

推荐答案

你不能使用git与子模块?例如在你.gitmodules文件,您可以添加这样的:

Couldn't you use git with submodules? e.g. In your .gitmodules file, you may add this:

[submodule "volley"]
path = volley
url = https://path/to/volley/repository 

您可以设置链接直接凌空的官方资料库,或您自己的内部版本抽射。其他项目可以设置以同样的方式,并指向相同的凌空库。

You can set the url to Volley's official repository, or to your own in-house version of volley. Other projects can be setup the same way and point to the same volley repository.

我觉得这样一来,其他用户可以调用 git的克隆和所有相关项目将主要的项目文件夹中下载,他们不必担心下载该库项目分开。

I think this way, other users can call git clone and all the dependent projects will be downloaded within the main project folder and they don't have to worry about downloading the library projects separately.

有关排球虽然,我只是把它编译成一个JAR文件,并将其贴到主体工程/ libs文件夹。也就是说,如果不需要修改其源

For Volley though, I would just compile it into a JAR file and stick it into the /libs folder of the main project. That is, if you don't need to modify its source.

[更新]
对于不需要修改其源库项目,你可以尝试使用Android Studio将其编译成AAR文件共享。 AAR文件就像一个JAR文件到Android,这样你就可以把它们添加到你的/ lib目录的源文件夹中,或者将它们发布到你的本地/ Intranet的Maven仓库。如果你选择了Maven的路线,加上本地/内部网资源库中的build.gradle,并引用你已经发布的库项目。

[Update] For library projects that you don't need to modify its source, you can try using Android Studio to compile them into AAR files for sharing. AAR file is like a JAR file to Android, so you can add them to your /lib source folder, or publish them to your local/intranet maven repository. If you choose the maven route, add your local/intranet repository in build.gradle, and reference the library project that you've published.

希望在未来更多的库项目业主将建立自己的项目进入AAR文件,并将它们发布到Maven的中央仓库,所以我们就可以从文件的build.gradle引用它们直接。

Hopefully in the future more Library projects owner will build their projects into AAR file and publish them to Maven Central Repository, so we can just reference them directly from the build.gradle file.

这篇关于使用Android Studio和gradle这个时候是否有可能项目之间共享库项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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