Android App Project Package Structure (Android Studio)
In our previous tutorial, we have learned how to create our first Android Application and how to run it. When we create an android project, Android studio generate the application project with a few default packages and folders. Here, in this tutorial we’ll discuss the project structure of an Android Application.
Here is a list of folders created, when you create an Android App project in Android Studio and see it in Project View Mode:
- app
- build
- libs
- src
- androidTest
- main
- java
- res
- AndroidManifest.xml
- Gradle
src folder
An androidTest package is created to hold Test cases to test the application code and run.
The androidTest package is created to hold Test cases to test an application code and running.
While the main folder consists of 2 folders and 1 file. They are:
java directory
This folder contains .java (JAVA) files. Here, you can create a new activity, adapter or fragment for your application.
This folder contains java code only and you can create separate packages for each of these and create classes inside them to give your application project a well defined structure.
AndroidManifest.xml
This file is a required file for any android application. In this file we provide information about all the application’s Activities, Services, Broadcast Receivers etc and all the permissions like Internet, Camera etc that our application will require when it is installed on any device. Just keep always in mind that this file is the heart of any Android Application.
res directory
This folder contains all the resources like images, icons etc related to our application project and it also contains the following sub-folders:
■ drawable
This folder contains xml, jpg, jpeg and png files. In this folder you can store images which can be used in your app and other .xml files which are used for many purposes like creating button background, or shadow effect etc.layout
■ layout
This folder have only the layout .xml files for different screens and parts of your application values
This folder contains default files like strings.xml, dimens.xml, colors.xml, styles.xml.
■ In strings.xml,you can specify all the string constants like title of screen or any other tag which will constantly used in your app.
■ In dimens.xml,you can create different .xml files to define dimensions as per resolution of screen and dimension of it and give any dimensions for padding, height, width, margin in this file.
■ In color.xmlyou can mention the list of colors using their hash codes, used in your application. If this is not created, then you can create this yourself.
■ In styles.xml you can define different readymade styles to use them directly anywhere in your Android App, also you can create your own styles.
gradle folder
In this folder there are files related to gradle which can be modified to alter the project building process. For example: If you really want to execute all the existing test cases before making the .apk file, you can do so by mentioning it in the gradle file.
- All your Java source code gets compiled into .class files by the Java compiler.
- All your .class files get converted into a single .dex file by the dx tool and also it is the part of Android SDK Tools.
- .dex file is a Dalvik Executable file that runs inside the Android Runtime(ART) when the app is launched.
- This .dex file is packaged with Android Manifest and other app resources files by Android Application Packaging Tool (aapt) to yield android package file, .apk, which is also called as android package.
- zipalignutility is used to optimize the .apk file, finally makes it ready for installation.