Skip to content

Directory Structure of an Android Project

The directory structure of an Android project is well-organized to manage code, resources, and configuration files efficiently. Understanding the project structure helps in maintaining, debugging, and scaling the app.


πŸ“‚ Android Project Directory Structure Overview

When you create a new Android project in Android Studio, the directory structure looks like this:

MyAndroidApp/
│── .gradle/
│── .idea/
│── app/
β”‚ │── src/
β”‚ β”‚ │── main/
β”‚ β”‚ β”‚ │── java/
β”‚ β”‚ β”‚ β”‚ │── com.example.myapp/
β”‚ β”‚ β”‚ β”‚ β”‚ │── MainActivity.java
β”‚ β”‚ β”‚ │── res/
β”‚ β”‚ β”‚ β”‚ │── layout/
β”‚ β”‚ β”‚ β”‚ β”‚ │── activity_main.xml
β”‚ β”‚ β”‚ β”‚ │── drawable/
β”‚ β”‚ β”‚ β”‚ │── mipmap/
β”‚ β”‚ β”‚ β”‚ │── values/
β”‚ β”‚ β”‚ β”‚ β”‚ │── strings.xml
β”‚ │── build.gradle (Module Level)
│── build/
│── gradle/
│── settings.gradle
│── gradle.properties
│── local.properties
│── build.gradle (Project Level)
│── AndroidManifest.xml


πŸ”Ή 1. Root Directory (Project Level)

The root directory contains essential files for the entire project.

File/FolderDescription
.gradle/Stores Gradle build files and caches.
.idea/Stores Android Studio settings & configurations.
build/Contains compiled files and generated APKs.
gradle/Contains Gradle wrapper scripts for project builds.
local.propertiesStores local system configurations (SDK path).
settings.gradleDefines which modules are included in the project.
build.gradle (Project Level)Configures project-wide Gradle settings.

πŸ”Ή 2. The app/ Module (Main Application Code)

The app/ module is where all application code and resources are stored.

Folder/FileDescription
src/Contains source code (main/, test/, androidTest/).
AndroidManifest.xmlDefines app components, permissions, and metadata.
build.gradle (Module Level)Defines dependencies, plugins, and configurations for the app module.

πŸ”Ή 3. The src/ Directory

This contains all the source code and resources.

FolderDescription
main/The main application source code and resources.
test/Contains unit tests (JUnit, Mockito).
androidTest/Contains UI and instrumented tests (Espresso, UIAutomator).

πŸ”Ή 4. The java/ Directory (Source Code)

Contains all the Java/Kotlin source code for the app.

app/src/main/java/com/example/myapp/
│── MainActivity.java
│── adapters/
│── models/
│── utils/
│── viewmodels/

Key Subdirectories:

βœ” adapters/ – Contains adapter classes for RecyclerView/ListView.
βœ” models/ – Defines data models (e.g., User.java).
βœ” utils/ – Utility/helper functions.
βœ” viewmodels/ – MVVM architecture ViewModels (if using Jetpack ViewModel).

πŸ”Ή Best Practice: Follow package by feature rather than package by layer.


πŸ”Ή 5. The res/ Directory (App Resources – UI & Assets)

This contains all the XML files for UI elements, images, themes, and app resources.

πŸ“ res/layout/ (UI Layouts)

Contains XML layout files for activities and fragments.

app/src/main/res/layout/
│── activity_main.xml
│── fragment_dashboard.xml
│── list_item.xml

πŸ“ res/drawable/ (Images & Shapes)

Stores vector assets, PNGs, backgrounds, and shape drawables.

app/src/main/res/drawable/
│── logo.png
│── button_background.xml

πŸ“ res/mipmap/ (App Icons)

Contains different resolution icons for the app launcher.

πŸ“ res/values/ (String, Colors, Dimensions)

Contains XML files for strings, colors, styles, and dimensions.

app/src/main/res/values/
│── strings.xml
│── colors.xml
│── styles.xml
│── dimens.xml

FilePurpose
strings.xmlStores text for localization & reusability.
colors.xmlDefines color codes for UI consistency.
styles.xmlDefines UI themes & styles.
dimens.xmlDefines margin, padding, text sizes.

πŸ”Ή Best Practice: Avoid hardcoding values directly in layoutsβ€”use values/ instead.


πŸ”Ή 6. The AndroidManifest.xml File

This defines app permissions, activities, services, and metadata.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:theme="@style/AppTheme"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

</application>
</manifest>

πŸ”Ή Key Elements:
βœ” uses-permission – Requests permissions (e.g., Internet, Camera).
βœ” application – Defines app-level settings like theme, backup.
βœ” activity – Declares activities and launch behavior.


πŸ”Ή 7. Gradle Build System

πŸ“Œ Project-level build.gradle (Global Configurations)

Located at root level (MyAndroidApp/build.gradle).

buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
}
}

πŸ“Œ Module-level build.gradle (App Configurations)

Located in app/build.gradle.

plugins {
id 'com.android.application'
}

android {
compileSdkVersion 33
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.5.0'
}

πŸ”Ή Important Configurations:
βœ” compileSdkVersion – Defines the Android SDK version used for compilation.
βœ” minSdkVersion – Minimum supported Android version.
βœ” dependencies – Lists external libraries used.


πŸ”Ή 8. The build/ Directory

  • Stores compiled APKs, dex files, generated resources.
  • Not included in version control (Git).

πŸ“ Summary: Why is Understanding the Directory Structure Important?

βœ… Helps in managing large projects efficiently.
βœ… Improves collaboration in teams.
βœ… Enhances debugging & maintenance.
βœ… Follows best practices for scalability & performance