模块与套件Android Studio [英] Modules vs Package Android Studio
问题描述
我是Android Studio和Java的新手.
I am very new to Android Studio and Java.
我正在开发应用程序.此应用基本上将遵循分层的架构,并具有不同的层,例如UI,数据访问层,服务层等.
I am in the process of developing an app. This app will basically follow a layered architecture, with different layers, for instance, the UI, Data Access Layer, Service layer etc.
我不清楚软件包和模块之间的区别.
I am not clear on the differences between packages and modules.
我的问题是,将所有这些不同的层放在模块或包中放在哪里?
My question is, where would one put all these different layers, in modules, or packages?
Pointing to @Angel reponse to this question, the only difference between the two is \, modules define a more strict rule by who can access them, by having to import the namespaces for the modules.
推荐答案
A 模块 是项目中源代码的容器.一个项目可以有多个模块,但是每个模块都是一组单独的代码和资源.
A module is the container for the source code within a project. A single project can have multiple modules, but each module is a separate set of code and resources.
例如,当您使用默认设置创建新项目时,Android Studio会生成一个名为app
的模块.该模块包含您应用程序的所有源代码,资源文件和应用程序级设置.
For instance, when you create a new project with the default settings, Android Studio generates a module called app
. This module holds all of the source code, resource files and app-level settings for your application.
但是,如果您使用Phone/Tablet应用程序以及Android Wear应用程序创建新项目,则会看到两个模块: mobile
和wear
.每个模块都包含各自应用程序的源代码,资源文件和应用程序级设置.
But, if you create a new project with a Phone/Tablet application as well as an Android Wear application, you will see two modules; mobile
and wear
. Each of these modules contain the source code, resource files and app-level settings for their respective application.
您还可以创建另一个模块,以在多个模块之间共享;该模块将被视为库模块.
You can also create another module to be shared between multiple modules; this module would be considered a library module.
软件包 是本质上是源代码所属的目录(文件夹).通常,这是一个唯一标识您的应用程序的目录结构.例如com.example.app
.然后,您可以在应用程序包中创建用于分隔代码的包;例如com.example.app.ui
或com.example.app.data
.
A package is essentially the directory (folder) to which source code belongs. Normally, this is a directory structure that uniquely identifies your application; such as com.example.app
. Then you can create packages within your application package that separates your code; such as com.example.app.ui
or com.example.app.data
.
因此,为回答您的问题,每个应用程序的软件包都位于应用程序模块的src/main/java
目录中.您可以在应用程序包中放置一个单独的包,以分隔应用程序体系结构的每个层".
Therefore, to answer your question, the package for each application resides within the src/main/java
directory of the application module. You could place a separate package within the application pacakge to separate each "layer" of your application architechture.
仅是一个可视示例,这是我的一个项目的基本结构:
Just for a visual example, this is the basic structure for one of my projects:
project
|-- build.gradle
|-- settings.gradle
~
|-- common // a common library module for both mobile and wear
| |-- build.gradle
| |-- proguard-rules.pro
| +-- src
| +-- main
| |-- AndroidManifest.xml
| |-- assets
| |-- java
| | +-- com
| | +-- example
| | +-- library // common module library package
| | |-- data
| | +-- util
| +-- res
|
|-- mobile // mobile application module
| |-- build.gradle
| |-- proguard-rules.pro
| +-- src
| +-- main
| |-- AndroidManifest.xml
| |-- assets
| |-- java
| | +-- com
| | +-- example
| | +-- app // mobile module application package
| | |-- data
| | |-- ui
| | +-- util
| +-- res
|
+-- wear // wear application module
|-- build.gradle
|-- proguard-rules.pro
+-- src
+-- main
|-- AndroidManifest.xml
|-- assets
|-- java
| +-- com
| +-- example
| +-- app // wear module application package
| |-- data
| |-- ui
| +-- util
+-- res
这篇关于模块与套件Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!