Android Studio使用modules
的概念,而Eclipse等其他IDE使用projects
。
但是,AS File
菜单可以选择创建New Module
以及new Project
。
这两者之间有什么区别?
建议使用哪一个?
答案 0 :(得分:165)
KISS回答:
Android Studio 中的模块就像 Eclipse中的项目
Android Studio 中的项目就像 Eclipse中的工作区
答案 1 :(得分:95)
来自the documentation(Android Studio基于Intellij IDEA):
无论您在IntelliJ IDEA中做什么,都可以在以下情况下执行此操作 项目。项目是代表a的组织单位 完整的软件解决方案。
您的成品可能会分解成一系列离散的, 孤立的模块,但它是一个带来它们的项目定义 在一起并将他们联系在一起。
对于Android,它表示每个应用程序一个项目,每个库和每个测试应用程序一个模块。
如果您尝试在同一个项目中构建多个应用,则会出现多个问题。这是可能的,但是如果你尝试(就像我一样),你会发现几乎所有东西都是为每个项目的单个应用程序而设计的。
例如,有一个“重建项目”的选项,这对于多个应用程序没有任何意义,许多其他项目设置将毫无用处,并且当您有多个存储库时,内置的VCS系统并不是很好。
答案 2 :(得分:32)
Android Studio 中的项目代表完整的Android应用。 Android Studio项目包含一个或多个 模块。
模块是您可以独立构建,测试或调试的应用程序组件。
模块包含应用的源代码和资源。
答案 3 :(得分:6)
模块为应用的源代码资源提供容器 文件和应用程序级别设置,例如模块级构建文件和 Android清单文件。每个模块都可以独立构建,测试, 并调试。
Android Studio使用模块可以轻松添加新设备 项目。通过Android Studio中的几个简单步骤,您可以 创建一个模块以包含特定于设备类型的代码,例如 作为Android Wear或Android TV。 Android Studio会自动创建 模块目录,例如源和资源目录,以及 适用于设备类型的默认build.gradle文件。也, Android Studio使用推荐的版本创建设备模块 配置,例如使用Android TV的Leanback库 模块。
例如:
除此之外,您还可以拥有一个"本地库模块"。比如说,您开发了一个帐户管理框架作为最终在您的应用程序中使用的库模块,您可以在同一个项目中将其作为一个单独的模块来实现。要在您的应用程序中包含它,您必须编写类似的内容,
compile project(':mylibrary')
文档说,
这声明了对名为的Android库模块的依赖 "在MyLibrary" (此名称必须与定义为的库名称匹配 包含在settings.gradle文件中。它需要构建系统 使用您的app模块编译库模块并包含 在APK中生成AAR文件。
最后,Intellij mentions有关模块配置文件的更多详细信息:
模块的配置信息存储在 .iml 模块中 文件。默认情况下,此类文件位于模块的内容根目录中 文件夹中。
开发团队通常会共享
.iml
个模块文件 版本控制。
这个.iml
文件有点可怕要查看。这是我项目的一个例子:
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="LearnCity" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":app" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res/layouts/common/layout/ver3/layout" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver3/layout;file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver3;file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver2/layout;file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver2;file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver1/layout;file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver1;file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver0/layout;file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver0;file://$MODULE_DIR$/src/main/res/layouts/common/layout;file://$MODULE_DIR$/src/main/res/layouts/learner/layout;file://$MODULE_DIR$/src/main/res/layouts/tutor/layout;file://$MODULE_DIR$/src/main/res/layouts/obsolete/layout;file://$MODULE_DIR$/src/main/res/layouts/common;file://$MODULE_DIR$/src/main/res/layouts/learner;file://$MODULE_DIR$/src/main/res/layouts/tutor;file://$MODULE_DIR$/src/main/res/layouts/obsolete;file://$MODULE_DIR$/src/main/res/layouts;file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/src/debug/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/google-services/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver3/layout" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver3" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver2/layout" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver2" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver1/layout" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver1" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver0/layout" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/common/layout/ver0" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/common/layout" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/learner/layout" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/tutor/layout" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/obsolete/layout" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/common" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/learner" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/tutor" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts/obsolete" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res/layouts" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/multi-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="google-http-client-android-1.22.0" level="project" />
<orderEntry type="library" exported="" name="firebase-analytics-10.2.0" level="project" />
<orderEntry type="library" exported="" name="firebase-core-10.2.0" level="project" />
<orderEntry type="library" exported="" name="play-services-auth-base-10.2.0" level="project" />
<orderEntry type="library" exported="" name="gson-2.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-tasks-10.2.0" level="project" />
<orderEntry type="library" exported="" name="constraint-layout-1.0.2" level="project" />
<orderEntry type="library" exported="" name="appengine-api-1.0-sdk-1.9.50" level="project" />
<orderEntry type="library" exported="" name="design-25.3.0" level="project" />
<orderEntry type="library" exported="" name="android-job-1.1.8" level="project" />
<orderEntry type="library" exported="" name="transition-25.3.0" level="project" />
<orderEntry type="library" exported="" name="play-services-base-10.2.0" level="project" />
<orderEntry type="library" exported="" name="multispinner-0.1.1" level="project" />
<orderEntry type="library" exported="" name="play-services-auth-10.2.0" level="project" />
<orderEntry type="library" exported="" name="support-core-ui-25.3.0" level="project" />
<orderEntry type="library" exported="" name="simpleratingbar-0.1.5" level="project" />
<orderEntry type="library" exported="" name="play-services-maps-10.2.0" level="project" />
<orderEntry type="library" exported="" name="play-services-location-10.2.0" level="project" />
<orderEntry type="library" exported="" name="firebase-iid-10.2.0" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-25.3.0" level="project" />
<orderEntry type="library" exported="" name="jsr305-2.0.1" level="project" />
<orderEntry type="library" exported="" name="support-fragment-25.3.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="multidex-instrumentation-1.0.1" level="project" />
<orderEntry type="library" exported="" name="constraint-layout-solver-1.0.2" level="project" />
<orderEntry type="library" exported="" name="androidannotations-api-3.2" level="project" />
<orderEntry type="library" exported="" name="java-uuid-generator-3.1.4" level="project" />
<orderEntry type="library" exported="" name="google-http-client-1.22.0" level="project" />
<orderEntry type="library" exported="" name="firebase-messaging-10.2.0" level="project" />
<orderEntry type="library" exported="" name="firebase-analytics-impl-10.2.0" level="project" />
<orderEntry type="library" exported="" name="firebase-common-10.2.0" level="project" />
<orderEntry type="library" exported="" name="eventbus-3.0.0" level="project" />
<orderEntry type="library" exported="" name="cat-1.0.5" level="project" />
<orderEntry type="library" exported="" name="play-services-basement-10.2.0" level="project" />
<orderEntry type="library" exported="" name="support-compat-25.3.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-25.3.0" level="project" />
<orderEntry type="library" exported="" name="multidex-1.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-25.3.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-25.3.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-25.3.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-25.3.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-25.3.0" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-25.3.0" level="project" />
<orderEntry type="module" module-name="backend" exported="" />
<orderEntry type="library" exported="" name="android-android-25" level="project" />
</component>
</module>
答案 4 :(得分:1)
IntelliJ IDEA为您使用的整个代码库创建一个项目,并为每个组件创建一个模块。因此,IntelliJ IDEA模块更像是Eclipse项目,而项目大致类似于Eclipse工作区。 Eclipse的工作空间并不完全等同于您的所有工作,但您可以同时在多个框架中打开多个项目。
以下是Eclipse用户页面的IntelliJ IDEA Q&amp; A -
http://www.jetbrains.com/idea/documentation/migration_faq.html
答案 5 :(得分:1)
模块就像apkLibs,即它有自己的res,清单,测试等,但主应用程序通常使用各种apklibs / modules来帮助将它们整合在一个解决方案中
答案 6 :(得分:0)
Android Studio 结构
Project <- Module <- Configuration
Project
合并单个或多个模块,模块可以没有、一个或多个配置(应用程序、测试...)
Module
用于分组、重用、构建时间目的。可以为应用程序或库/框架创建
单个项目允许您管理在同一业务项目范围内可能遇到的所有案例。例如你正在开发一些 SDK,这就是为什么你应该有 SDK 模块,你也应该通过 Demo Application(每个用于 Java 和 Kotlin 语言)提供消费者,这就是为什么你创建包含你的 SDK 的应用程序模块,然后你决定模块化您的 SDK 并创建单独的模块,它们之间存在依赖关系。
答案 7 :(得分:-5)
参考@Oded Breiner回答我会说:
Android Studio 中的模块就像 Eclipse中的项目
Android Studio 中的项目就像 Eclipse中的工作集