在机器人工作室的Andr​​oid库 [英] Android Libraries in Android Studio

查看:98
本文介绍了在机器人工作室的Andr​​oid库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人想出/发现了如何的Andr​​oid库的目的是在Android的工作室工作?

Has anyone figured/found out how Android libraries are intended to work in Android studio?

我一直没能找到有关此的任何文件,但(在Android开发者网站上的文档是令人难以置信的裸去骨),我观察到这取决于我如何创建库项目中,我得到完全不同的结果。

I have not been able to find any documentation on this yet (the documentation on the Android Developer Site is incredibly bare-boned), and I observe that depending on how I create the library project, I get completely different results.

如果我从导入的Eclipse库(以下网站上的建议,以出口到摇篮第一),我结束了包含库项目中的新项目+模块。这似乎不是很正确(一个项目的IntelliJ =日食工作区),并试图编译/使这个在很多错误的IntelliJ结果(库项目无法找到Android的支持库)。

If I import a library from Eclipse (following the recommendations on the website to export to Gradle first) I end up with a new project + module containing the library project. This does not seem quite right (an intellij project = eclipse workspace), and attempts to compile/make this in intellij results in many errors (the library project can't find the android support libraries).

如果我从头开始创建一个新的项目库模块,然后我得到一个Android库项目与build.gradle文件。

If I create a new project from scratch with a library module, then I get an android library project with a build.gradle file.

如果我创建一个新的模块从项目中(使用右键单击该项目),然后我得到使用Ant一个Android库建成。编译没有问题,但似乎很奇怪。当然,这并不意味着,我们应该使用Ant在机器人工作室的Andr​​oid库?创建文件使用一个新的库模块>新建模块似乎没有工作,顺便说一句。它只是创建了一个新的应用程序,而不是。

If I create a new module from within a project (using right click on the project), then I get an Android library built using Ant. This compiles fine, but seems very odd. Surely it is not intended that we should use Ant for Android libraries in android Studio? Creating a new library module using File > New Module doesn't seem to work, incidentally. It just creates a new application instead.

有没有人捡到的任何信息,使这个有意义吗?我还没有发现其中一个可以指定库应该在应用模块中使用的任何位置。我明白这是一个preVIEW发布,但我有很难相信,像Android的图书​​馆的核心功能是支持如此糟糕。我在想什么?

Has anyone picked up any information to make sense of this? I also haven't found any location where one can specify which libraries should be used in which application modules. I understand this is a preview release, but I'm having difficulty believing that a core feature like Android libraries is so poorly supported. What am I missing?

更新2014年4月9日:

Update 2014-04-09:

所以,这周我采取了新一轮与Android工作室。虽然现在的问题比我最初写这个不同,这是 - 相当令人难以置信的 - 仍然是一个大问题。我还没有发现使用的是Android库在多个项目中的AS(包括嵌套库)的一个很好的解释。一些我见过的建议,建议复制code到多个位置 - 它完全违背了一个图书馆开始与目的。

So I took a new round with Android Studio this week. And while the problems now are different than when I originally wrote this, this is - quite incredibly - still a big problem. I've still not found a good explanation of using Android libraries in multiple projects in AS (including nested libs). Some of the suggestions I've seen recommend copying code into multiple locations - which completely defeats the purpose of having a library to begin with.

我只是不明白这是什么谷歌正在考虑与Android工作室......这是一个遗憾,因为它似乎是一个伟大的工具,但缺乏一个直观的处理东西,所以基本为code重用是一个很大问题对我来说(不要介意编码专为Android正变得越来越没有吸引力,相对于不断提高跨平台开发工具)。

I just don't get what Google are thinking with Android Studio... It's a pity, because it seems like a great tool, but the lack of an intuitive handling something so basic as code reuse is a big issue for me (never mind that coding specifically for Android is becoming less and less attractive, when compared to the ever-improving cross-platform development tools).

推荐答案

为了任何人打这个的,这里是我在做什么解决这个问题。这是从很远的一流解决方案,国际海事组织,但它是最接近我已经找到了为使用Git处理我的问题(重复使用的Andr​​oid库)在Android的Studio中的一个很好的解决方案。

For the sake of anyone hitting on this, here's what I'm doing to "solve" this issue. It's very far from an elegant solution, IMO, but it's the closest to a good solution that I've found for handling my problem (reusing Android libraries) in Android Studio with Git.

基本思想是使用GIT中的子模块。每个图书馆都有它自己的Git仓库。

Basic idea is to use Git submodules. Each library has it's own Git repository.

  1. 创建MyLibrary的为一个模块,然后将其提交到资源库。
  2. 从项目的根库,我做了一个 git的子模块添加来获取库。
  3. 在settings.gradle,我补充一下:包括:在MyLibrary和同步的项目
  4. 在模块设置>>依赖性>> +模块依赖,并添加相关的模块合适。
  1. Create myLibrary as a module, and then commit it to a repository.
  2. From the project root repository, I do an git submodule add to fetch the library.
  3. In settings.gradle, I add: include ':myLibrary' and sync the project.
  4. Module Settings >> Dependencies >> + Module Dependency and add a dependency to the module as appropriate.

这是一个相去甚远在Eclipse中的Andr​​oid库工作的古朴典雅,但一种时尚后,它的工作原理。事情要记住:

It's a far cry from the simple elegance of working with Android libraries in Eclipse, but it works after a fashion. Things to keep in mind:

  • 记住的git拉频繁,拿起变化(然后提交主体工程的子模块的变化同步)。
  • 记得从模块目录到远程的git推,如果你提交更改到库中。

内置的VCS应能有所帮助,但它一直pretty的片状我,所以我preFER只是做我自己从一个终端了。

The built-in VCS should be able to help here, but it's been pretty flaky for me, so I prefer to just do it myself from a terminal now.

希望这有助于。

这篇关于在机器人工作室的Andr​​oid库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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