Android的Studio项目结构(与Eclipse的项目结构) [英] Android Studio Project Structure (v.s. Eclipse Project Structure)

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

问题描述

我想学习Android开发,我最初是由Eclipse和Android的工作室之间的不同的项目结构相混淆。这使得难以遵循专为Eclipse的教程吧。任何人都可以让我知道为什么这些差异的存在?他们是否应该存在?

I'm trying to learn android development and I am initially confused by the different project structures between Eclipse and Android Studio. This makes it difficult to follow tutorials designed for Eclipse. Could anyone let me know why these differences exist? Should they exist?

举例来说,如果我找到了两个不同的IDE的R.java文件,路径是这样的:

For instance, if I were to locate the R.java file in the two different IDEs, the paths would look like this:

的Eclipse:应用\根\ com.example.app \ R.java

Eclipse: app\gen\com.example.app\R.java

Android的工作室:应用\生成\来源\ r \调试\ com.example.app \ R.java

Android Studio: app\build\source\r\debug\com.example.app\R.java

为什么这些路径不同?为什么我的R.java位于机器人Studio中的debug文件夹?这导致一些错误早期,如果任何人有任何深入了解这些差异我想AP preciate他们。

Why are these paths different? Why is my R.java located in a debug folder in Android Studio? This lead to some errors early on, and if anyone has any insight into these differences I would appreciate them.

推荐答案

我不知道这是因为摇篮构建系统(我打赌它是),但我会告诉你什么是我到目前为止的理解。

The mystery: Android Studio's Project Structure and Build System

I don't know if this is because of the Gradle Build System (I'd wager it is), but I'll tell you what I've understood so far.

更新4: 2014年9月11日新增的骗取 BuildTypes 香料变体(我终于有信心写这篇文章:D)
更新3: 2014年9月11日更新的比较工作区和项目为precise
更新2: 2014年4月17日增加了更多的AS项目结构
细节 更新1: 2013年7月29日新增的IntelliJ项目结构

Update 4: 2014/09/11 Added Cheat Sheet for BuildTypes, Flavors and Variants(I finally feel confident to write this :D)
Update 3: 2014/09/11 Updated the comparison workspaces and projects to be precise
Update 2: 2014/04/17 Added more detail to AS project structure
Update 1: 2013/07/29 Added IntelliJ Project Structure

在的IntelliJ的项目结构(在末尾显示)的IntelliJ与Android插件。 Android的工作室,但是,有一个项目的结构划分如下所示:

The IntelliJ's Project structure (shown at the end) is for IntelliJ with the android plugin. The Android Studio, however, has a project structure divided like so:

模块中的 Android的工作室的是像项目中的的Eclipse

项目中的 Android的工作室的是像工作区中的的Eclipse 的(是precise,一工作区与相互依存的项目)

project in Android Studio is like a workspace in Eclipse (to be precise, a workspace with interdependent projects)

的文档(Android的Studio是基于IntelliJ IDEA的):

From the documentation (Android Studio is based on Intellij IDEA) :

无论你在IntelliJ IDEA的做,你这样做,在一个范围内   项目。一个项目是重新presents一个组织单位   完整的软件解决方案。

Whatever you do in IntelliJ IDEA, you do that in the context of a project. A project is an organizational unit that represents a complete software solution.

您成品可以被分解成一系列不连续的,   隔离模块,但它是一个项目的定义,使他们   一起捆绑成一个更大的整体。

Your finished product may be decomposed into a series of discrete, isolated modules, but it's a project definition that brings them together and ties them into a greater whole.

有关Android的,这意味着每个应用程序的一个项目,每库和每个测试程序一个模块。

For Android, it means one project per app, and one module per library and per test app.

有,如果你尝试在同一项目内建设多个应用程序的多个问题。这是可能的,但如果你试图(像我一样),你会看到,几乎所有的设计,每个项目一个单一的应用程序工作。

There are multiple issues if you try to build multiple apps within the same project. It's possible, but if you try (like I did), you will see that almost everything is designed to work with a single app per project.

例如,有一个选项,以重建工程,这是没有意义的与多个应用程序,许多其他项目设置将是无用的,当你有多个存储库内置的VCS系统也不是很大。

For example, there is an option to "rebuild the project", which makes no sense with multiple apps, many other project settings would be useless, and the built-in VCS system isn't great when you have multiple repositories.

这将是整个项目环境 Eclipse的土地:就像你的工作空间,但仅限于有什么相关的项目)。例如: HelloWorldProject ,如果你给是应用程序的名称的HelloWorld

This would be entire project context (Eclipse Land: Like your workspace but limited to what's relevant to your project). Ex: HelloWorldProject if the name of the application you gave was HelloWorld

这其中,项目特定的元数据是由机器人工作室(AS)存储。 ( Eclipse的土地: project.properties 文件)

This where project specific metadata is stored by Android Studio (AS). (Eclipse Land: project.properties file)

这是实际的项目。例如:的HelloWorld ,如果你给你的应用程序的名字是的HelloWorld

This is the actual project. ex: HelloWorld if your application name you gave was HelloWorld

这是那里的摇篮构建系统的瓶子包装,即这个罐子是多么的AS摇篮安装在Windows(在我的情况下,OS)。通讯

This is where the gradle build system's jar wrapper i.e. this jar is how AS communicates with gradle installed in Windows (the OS in my case).

这实际上不是一个文件夹,但是,其中所引用库的地方( Eclipse的土地:引用的库)显示。在此处,目标平台显示等。

This is not actually a folder but a place where Referenced Libraries (Eclipse Land: Referenced Libraries) are shown. Here's where the Targeted Platform is shown etc.

[边注:这其中,我们很多人在Eclipse土地用于删除引用的库和修复项目属性来解决引用错误,请记住]

[Side note: This where many of us in Eclipse Land used to delete the referenced libraries and Fix Project Properties to fix reference errors, remember?]

这是在上面的列表号#3。有以下子迪尔斯

This is number #3 in the above list. Has the following sub dirs

这有工艺,即classes.dex所有完整的输出,编译类和资源等。

This has all the complete output of the make process i.e. classes.dex, compiled classes and resources, etc.

在机器人工作室GUI中,只有少数的文件夹被示出。最重要的是,您R.java在这里找到 建立/源/<味道> / R /<建设型(可选)GT; / <包装> /R.java

In the Android Studio GUI, only a few folders are shown. The important part is that your R.java is found here under build/source/<flavor>/r/<build type(optional)>/<package>/R.java

这是您在看到标准的libs文件夹中的日食土地

This is the standard libs folder that you see in eclipse land too

在这里,你只看到的Java RES 文件夹对应于 SRC 文件夹和 RES 文件夹中的 Eclipse的土地。这是值得欢迎的简化恕我直言。

Here, you only see the java and res folder which correspond to the src folder and res folder in Eclipse Land. This is much welcomed simplification IMHO.

模块就像 Eclipse的土地项目。这里的想法是,你有一个应用程序项目(模块在上面的列表#3)和几个库项目(如在全球项目文件夹(在上面的列表#1)独立的模块)的应用项目依赖。如何将这些库项目可以重新用在其他应用中,我还没有发现。

Modules are like Eclipse Land projects. Here the idea is that you have one application project (Module #3 in the list above) and several library projects(as separate Modules under the global project folder (#1 in the above list)) which the application project depends on. How these library projects can be re-used in other applications, I still haven't found out.

[边注:整体重新组织有一个像简化在src文件夹,但这么多复杂一些好处。并发症,主要是由于非常非常薄文档在这个新的项目布局。]

[Side note: The whole re-organization has some benefits like simplifications in src folder, but so many complications. The complications are mainly due VERY VERY thin documentation on this new project layout.]

用户指南新构建系统

BuildType: 调试发布 buildTypes 默认提供的所有项目。他们是建筑/编译 SAME code ,以产生不同的APK。例如关于发布的APK你想运行的优化(也许通过ProGuard的或其他运行ProGuard的(对于混淆),与你的密钥进行签名(作为对调试键),工具),使用略有不同的 packageNames (我们使用 com.company.product 发布 com.company.product.debug 调试),等等。我们还使用了调试标志( BuildConfig.DEBUG )关闭记录到logcat的(因为它使应用程序慢)的发布构建。这使得更快调试的发展过程中建立也是一个优化的发布建设投入玩店。

BuildType: debug and release are buildTypes available by default on all projects. They are for building/compiling the SAME CODE to generate different APKs. For example on release APKs you would want to run proguard(for obfuscation), sign it with your key (as against the debug key), run optimizations (maybe via proguard or other tools), use slightly different packageNames (we use com.company.product for release and com.company.product.debug for debug), etc. We also use a debug flag (BuildConfig.DEBUG) to turn off logging to logcat (since it makes the app slow) on release builds. This makes for a faster debug build during development but also an optimized release build to put on play store.

产品风味:有没有可用的默认香精(或为precise,默认的味道是空白/无名)。 香精可能是免费版付费版本他们在那里的不同code 。它们共享相同的 code,但不同的版本(或者没有版本)的数源$ C ​​$ C文件或资源。

Product Flavor: There are no default flavors available (or to be precise, the default flavor is blank/nameless). Flavors could be free version or paid version where they have DIFFERENT CODE. They share the same Main Code but different versions(or no versions) of a few source code files or resources.

BuildVariant: A buildVariant 是一个生成APK实际上对应。它们被命名为像这样(按顺序)的 产品风味 + 构件类型 = 变化范围
示例1:如果您有免费支付的两种口味。构建变种,你将得到的是:
    免费 - 调试
    免费 - 发行
    付费 - 调试
    支付 - 释放
所以这是4个可能的APK配置。一些配置可能是没有意义的特定项目,但他们的可用。

BuildVariant: A buildVariant is what a generated APK actually corresponds to. They are named like so (in order) Product Flavor + Build Type = Build Variant.
Example 1: if you have free and paid as two flavors. The build variants you would get are:
Free - debug
Free - release
Paid - debug
Paid - release
So that is 4 possible APK configurations. A few configurations may not make sense in a particular project, but they are available.

示例2:(新项目/无香精)你有2 buildVariants 或的APK可用,因为默认的味道无名/空白:
    调试
    发布

Example 2: (for new projects/ no flavors) You have 2 buildVariants or APKs available, since the default flavor is nameless/blank:
debug
release

的.idea(1)文件夹中包含了一些子文件夹,这主要与内部IntelliJ IDEA的信息。

The .idea (1) folder contains a number of subfolders, mainly with internal IntelliJ IDEA information.

的SRC(2)文件夹包含MyActivity.java (3)文件源$ C ​​$ C 实现您的应用程序的功能。该文件属于com.example包。

The src (2) folder contains the MyActivity.java (3) file source code that implements the functionality of your application. The file belongs to the com.example package.

的RES(4)文件夹中包含了各种视觉资源。

The res (4) folder contains various visual resources.

布局/ main.xml中的文件(5)定义各类资源的应用程序的外观构成。

The layout/main.xml file (5) defines the appearance of the application constituted of resources of various types.

的值文件夹(6)是用于存储的.xml描述不同类型的资源文件。 presently,该文件夹包含字符串资源定义一个的strings.xml文件。如你将从添加颜色部分看到,布局文件夹也可以包含,例如,颜色描述符。

The values folder (6) is intended for storing .xml files that describe resources of various types. Presently, the folder contains a strings.xml file with String resources definitions. As you will see from the Adding a Color section, the layout folder can also contain, for example, a descriptor of colors.

的绘制文件夹(7)包含图像。

的根(8)文件夹包含在 R.java(9)文件链接的视觉资源和Java源代码code。正如您将从下面的部分看,IntelliJ IDEA的支持静态资源和R.java之间的紧密集成。只要任何资源添加或删除,在R.java对应的类和类字段自动生成或相应免除。该R.java文件也属于com.example包。

The gen (8) folder contains the R.java (9) file that links the visual resources and the Java source code. As you will see from the sections below, IntelliJ IDEA supports tight integration between static resources and R.java. As soon as any resources are added or removed, the corresponding classes and class fields in R.java are automatically generated or removed accordingly. The R.java file also belongs to the com.example package.

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

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