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/Folder | Description | 
|---|---|
.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.properties | Stores local system configurations (SDK path). | 
settings.gradle | Defines 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/File | Description | 
|---|---|
src/ | Contains source code (main/, test/, androidTest/). | 
AndroidManifest.xml | Defines 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.
| Folder | Description | 
|---|---|
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  
| File | Purpose | 
|---|---|
strings.xml | Stores text for localization & reusability. | 
colors.xml | Defines color codes for UI consistency. | 
styles.xml | Defines UI themes & styles. | 
dimens.xml | Defines 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
