In this article, we will examine the Android Studio project structure and key concepts in detail followed by compilers. When we start a new Android project in Android Studio, it will automatically create a lot of files and folders for us. Let’s look at their functions and meaning. A New Project automatically opens in the Android Project View.
Table of Contents
- 1 Android Project View
- 2 Android Manifest File
- 3 java
- 4 res
- 5 Gradle Scripts
- 6 The Project View
- 7 .idea
- 8 Project Module(app)
- 9 Gradle
- 10 External Libraries
- 11 What is R.java?
- 12 Android Compilers
- 13 DEX
- 14 Android ProGuard
Android Project View
The Android project view shows all the build files at the top level of the project hierarchy under Gradle Scripts. Each project module appears as a folder at the top level of the project hierarchy and contains these three elements at the top level:
- > java/: Source files for the module.
- > manifests/ : Manifest files for the module
- > res/ : Resource files for the module
Here is the brief description of important files/folders in the Android project structure:
Android Manifest File
AndroidManifest.xml
is one of the most important files in the Android project structure. It contains information on the package, including components of the application such as activities, services, broadcast receivers, content providers, etc.It performs the following tasks:
- > It is responsible to protect the application to access any protected parts by providing the permissions
- > It also declares the android API that the application is going to use
- > It lists the instrumentation classes. The instrumentation classes provide profiling and other information. This information is removed just before the application is published etc.
java
The java folder contains the Java source code files of the application organized into packages. We can have more than one package in the Android application. It's always a good practice to break the source code of the application into different packages based on its core functionality. All the source files of the Activities, Services, etc. go into this folder.res
Res folder is where all the external resources for the application such as images, layout XML files, strings, animations, audio files, etc. are stored.Subfolders:- Drawable: This folder contains the bitmap file to be used in the program. There are different folders to store drawable. They are drawable-ldpi, drawable-mdpi, drawable-hdpi,drawable-xdpi, etc. The folders are to provide alternative image resources to specific screen configurations. Ldpi, mdpi & hdpi stands for low density, medium density & high-density screens respectively. The resources for each screen resolutions are stored in respective folders and the android system will choose it according to the pixel density of the device
- Layout: It contains XML files that define the User Interface of the application
- Menu: XML files that define menus for the application goes into this folder
- Mipmap: The mipmap folders is used for placing the app icons only. Any other drawable assets should be placed in the relevant drawable folders as before.
- Values: XML files that define simple values such as strings, arrays, integers, dimensions, colors, styles, etc. are placed in this folder
Gradle Scripts
Gradle scripts are used to automate tasks. For the most part, Android Studio performs application builds in the background without any intervention from the developer. This build process is handled using the Gradle system, an automated build toolkit designed to allow the ways in which projects are built to be configured and managed through a set of build configuration files. It uses a language called groovy.The Project View
idea
Eclipse uses the project.properties file for project-specific metadata. Here in Android Studio, this .idea does the same thing. This means the project-specific metadata is stored by Android Studio.
Project Module(app)
This is the actual project folder where the application code resides. The application folder has the following subdirectories
- build: This has all the complete output of the making process i.e. classes.dex, compiled classes, and resources, etc. In the Android Studio GUI, only a few folders are shown. The important part is that the R.java is found here under build/generated/source/r/…/R.java
- libs: This is a commonly seen folder in eclipse and android studio, which optionally can hold the libraries or .jar files
- src: The src folder can have both application code and android unit test script. You will find two folders named “android test” and “main” correspond to the src folder. The main folder contains two subfolders java and res. The java folder contains all the java codes and res contains drawable, layouts, etc.
Gradle
This is where the Gradle build systems jar wrapper is found. This jar is how Android Studio communicates with Gradle installed in Windows/MAC.
External Libraries
This is not actually a folder but a place where Referenced Libraries and information on targeted platform SDK are shown.
What is R.java?
Android R.java is an auto-generated file by AAPT (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory.
On creating any component in the activity_main.xml file, id for the corresponding component is automatically created in this file. This id can be used in the activity source file to perform any action on the component.
On creating any component in the activity_main.xml file, id for the corresponding component is automatically created in this file. This id can be used in the activity source file to perform any action on the component.
Android Compilers
The compilers convert compiled .class files to executable .dex files in the Dalvik format for further execution in the Android environment. Following are the two important tools used:
DEX
Dalvik Virtual Machine is an Android Virtual Machine optimized for mobile devices. It optimizes the virtual machine for memory, battery life, and performance. The Dex compiler converts the class files into the .dex file that runs on the Dalvik Virtual Machine. The Multiple class files are converted into one dex file. Following flow depicts compiling and packaging process from the source file:
- > The javac tool compiles the java source file into the class file.
- > The dx tool takes all the class files of the application and generates a single .dex file. It is a platform-specific tool.
- > The Android Assets Packaging Tool (AAPT) handles the packaging process.
0 Comments