Greetings!We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners. Also, if you are interested in content writing, you can mail us at firstname.lastname@example.org.
In this tutorial, we will learn about android project structure created using android studio. A project, in android studio, contains everything that defines workspace for an app, from source code and assets, to test code and build configurations. Whenever any project is created, Android studio creates basic folder structures that can be used
A. to write code to do the things dynamically.
B. to write code to show the UI.
C. to store images, audio, videos or other media files.
D. to change the UI based on the device configurations.
E. to test the functionality of application.
F. to build the application and store application apk file.
We will see about each thing separately later in this post.
Creating New Project
At first, we will create project. So, follow steps written below to create a new project.
a. Go to File => New => New Project. Then, write application name as Hello World and click next.
b. Select Minimum SDK => click next => Select Empty Activity => click next => click finish.
If you have followed above process correctly, you will get a newly created project successfully.
If you want to know more about creating a new project, you can visit Creating new Project
You can see created project in different modes. These modes are available at left-top corner.
Whenever a new project is created, it’s default view is shown in Android Mode. In Android Mode, you will see only app module related things. Since we are going to see the folder structure, we need to change this mode to Project. It will show maximum details about the project. You just need to select Project mode from the dropdown menus.
Project Folder Structures
Folder structure in the newly created project in Project mode would look like below.
Different folders and files are as below –
HelloWorld: This is project root directory.
.gradle: In this folder, you can find all the settings and files used by gradle to build the project. You can delete these files if you want. These files will be created when you will build the project again.
.idea: Android Studio stores project specific meta-data in this folder. It contains a set of configuration files. Each file contains configuration data for a certain functional area. The name of the file explain the functional area itself. For example, compiler.xml, encodings.xml, modules.xml file etc.
app: This is actual project folder where code related to project is stored. Here, you write code, create UI, stores assets etc. We will discuss about this section in detail soon.
build: This folder contains build related data. Data is generated when you build the project.
gradle: You would notice that there is wrapper folder inside this. When you distribute the wrapper with your project, anyone can work on the project without installing the Gradle. Another advantage is other users are guaranteed to use same version of Gradle that build was designed to work properly.
.gitignore: We include all the files in this folder that we want to exclude from version control system.
buld.gradle: This is a top-level build file where we add configuration options common to all sub-projects/modules. This is different from app/build.gradle file.
gradle.properties: This is where you configure project-wide Gradle settings. For example, Gradle daemon’s maximum heap size etc.
gradlew: This file is related to gradle. It is created once and updated when a new feature or plugin is required that needs updated gradle version.
gradlew.bat: This file is related to gradle. It is created once and updated when a new feature or plugin is required that needs updated gradle version.
HelloWorld.iml: This is a module file created by IntelliJ IDEA, an IDE used to develop Java applications. It stores information about a development module, which may be a Java, Plugin, Android, or Maven component; saves the module paths, dependencies, and other settings.
local.properties: It contains information specific to your local configuration. For example, path to SDK etc. Since it contains local information, it should not be checked into version control system.
settings.gradle: This file handles project, module and other kinds of names and settings,
External Libraries: This is not actually a folder but a place where referenced libraries are shown.
Now, We will see the app section in detail.
App Section Structures
App section looks like below.
app folder has following files and sub-folders.
app/build: This contains output generated when we run the application. i.e. It contains build outputs.
app/libs: It contains libraries being used with this app module.
app/src: It contains all code and resource files(images, audio, video etc.) that are needed in the app module. It has sub folders too. We will discuss, in detail, about this later.
app/.gitignore: We include all the files(present in the app module) that we do not want to check into version control system.
app/app.iml: IML is a module file created by IntelliJ IDEA, an IDE used to develop Java applications. It stores information about a development module, which may be a Java plugin, Android, or Maven component, saves the module paths, dependencies, and other settings.
app/build.gradle: This file contains build configurations specific to this app module.
app/proguard-rules.pro: This is where we add custom ProGuard rules. ProGuard detects and removes unused classes, fields, methods and attributes from your packaged app, including those from included code libraries. It also optimises the byte code, removed unused code instructions, and obfuscates the remaining classes, fields, and methods with short names. The obfuscated code make the APK difficult to reverse engineer, which is extremely valuable, especially when we have payment related information.
Now, coming to the app/src sections.
App/src Section Structures
This section contains source code and all resources that we need to build any application. Below image shows the structure.
It has three sub-folders – androidTest, main and test.
androidTest: We write code into this folder to perform unit testing that need android device or emulator. These tests will have access to instrumentation information. For example, context of the app you are testing. So, write code into this folder to test the code that use Android framework. Moreover, Use this folder when your tests have android dependencies that mock objects can not satisfy.
main: This contains the main source-code(Android code and resource files), that we need to build project. We will talk about this later.
test: We write code into this folder to perform unit testing that do not need android device or emulator. These tests run locally on the Java Virtual Machine(JVM). Use these test to minimize execution time when tests have no Android framework dependencies or when you can mock android framework dependencies.
Now, coming to the main folder.
App/src/main Section Structures
This folder contains the actual android code and resource files. Below image clearly depicts the folder structure.
This folder contains following files and sub-folders.
AndroidManifest.xml: You must have this file in any android application. It describes the nature of the application and each of its components. it also contains the name of java package of the application that serves as unique identifier for the application. It also contains minimum android API level that application requires.
java: This folder contains java code source.
res: It contains application resources, such as drawable files, layout files, and UI string, dimension, colors etc. This folder also has sub-folders as below. Below are the sub-folder that resides inside res folder –
res/drawable: This folder contains drawable xml files and images.
res/mipmap: This folder contains launcher icon.
res/values: In values folder, we store different values used in the application. For example, different colours, dimensions, strings, styles used in the application. They are basically used to remove hardcoded value in the application. This also helps in resource localisation and internationalisation.
This folder contains a separate file for each type of values. They are –
res/values/colors.xml: This file contains different colors used in the application.
res/values/dimens.xml: This file contains different dimension used in the application.
res/values/strings.xml: This file contains different strings used in the application.
res/values/styles.xml: This file contains different styles used in the application.
Other folder in res folder –
res/raw: You can create this folder in res folder and store audio, video etc. into it.
This tutorial covers android project structure when you create any project using android studio. We have tried to cover the topic in detail. If you have any query, please feel free to contact us at below contacts.