I am very new to Android Studio and Java.
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 module is a file containing Python code in run time for a user-specific code. A package also modifies the user interpreted code in such a way that it gets easily functioned in the run time.
Modules. A module is a collection of source files and build settings that allow you to divide your project into discrete units of functionality. Your project can have one or many modules, and one module may use another module as a dependency. You can independently build, test, and debug each module.
The output of an app module is an APK, the package of an Android application. A library is a collection of code that represents something that you want to use in multiple applications or otherwise want to keep in a separate "container" than the rest of the app code. The output of a library module is an AAR.
A module is a collection of related Java packages and associated resources with a descriptor file, which contains information about which packages/resources are exposed by this module, which packages are used by current module and some other information.
A single project can have multiple modules, but each module is a separate set of code and resources. 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.
A Python module is a .py file with function(s) and/or class(es) that you can reuse in your code. You can also create your own. A Python package is a directory of such modules. A package often holds modules of a kind together, along with an __init__.py file.
A single project can have multiple modules, but each module is a separate set of code and resources. For instance, when you create a new project with the default settings, Android Studio generates a module called app.
1 Answer 1. 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. For instance, when you create a new project with the default settings, Android Studio generates a module called app.
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.
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.
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.
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With