Visit Sponsor

Written by 4:34 pm Android

Android Studio Project Structure – Developer Guide

Overview

Android Studio is the official IDE for Android development. Its project structure is designed to organize source code, resources, and build configurations in a consistent and scalable manner. Understanding this structure is essential for navigating, maintaining, and scaling Android applications.

This document explains the key components of an Android Studio project, including modules, manifests, resource directories, build files, and Gradle configuration.

Project Root and Gradle Files

At the top level of an Android Studio project you will find:

<project_name>/
├── build.gradle (Project)
├── settings.gradle
├── gradle/
├── gradlew
├── gradlew.bat
└── app/

Key Elements

  • build.gradle (Project Level):
    Defines global configuration, repositories, classpaths, and plugin versions.
  • settings.gradle:
    Lists the modules included in the project.
  • gradlew & gradlew.bat:
    Gradle wrapper scripts for Unix and Windows systems, ensuring consistent Gradle versions.
  • gradle/ directory:
    Contains supporting Gradle configuration files.

App Module and Its Structure

The app/ directory contains the main module of your Android application:

app/
├── build.gradle (Module Level)
├── src/
│   ├── main/
│   │   ├── java/
│   │   ├── res/
│   │   ├── AndroidManifest.xml
│   │   └── assets/
│   ├── androidTest/
│   └── test/
└── libs/

Module-Level build.gradle

Each module has its own build.gradle that defines:

  • compileSdkVersion
  • minSdkVersion / targetSdkVersion
  • Dependencies (libraries, support libs, etc.)
  • Build types (debug, release)
  • Flavor configurations (if any)

Example snippet:

android {
    compileSdkVersion 33
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.9.0'
}

Source Sets in src/

The src/ directory contains all source files and resources structured by build variants and test types.

/main

The main source set includes:

  • java/ — Java or Kotlin source code
  • res/ — App resources like layouts, drawables, strings
  • AndroidManifest.xml — App manifest defining components and permissions
  • assets/ — Raw files packaged in the APK (optional)

Example hierarchy:

src/main/java/com/example/app/MainActivity.java
src/main/res/layout/activity_main.xml
src/main/res/values/strings.xml
src/main/AndroidManifest.xml

Resource Directories (res/)

Android resources are organized by type:

DirectoryPurpose
drawable/Images and graphic assets
layout/UI layout XML files
values/Strings, colors, themes, styles
mipmap/Launcher icons
anim/Animation XML
menu/Menu resource XML

Resources are automatically compiled and referenced via generated IDs.

Example:

<TextView
    android:id="@+id/helloText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"/>

AndroidManifest.xml

The manifest file is required for every Android application. It declares:

  • App package name
  • Activities, Services, BroadcastReceivers
  • Permissions (e.g., INTERNET, ACCESS_FINE_LOCATION)
  • Minimum SDK requirements

Example:

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

    <application
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher">
        <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>

Testing Source Sets

Android Studio provides dedicated directories for testing:

  • androidTest/ – UI and instrumentation tests
  • test/ – Local unit tests

Example:

src/androidTest/java/…
src/test/java/…

Use Gradle tasks such as connectedAndroidTest and test to execute these tests.

Gradle Build Variants and Flavors

Gradle supports build variants, which combine build types and product flavors.

Build Types

  • debug – For development
  • release – For production distribution

Product Flavors (Optional)

You can define flavors (e.g., free, paid) to create multiple APK variants with different features or branding.

Example:

flavorDimensions "version"
productFlavors {
    free {}
    paid {}
}

This generates variants such as freeDebug, paidRelease, etc.

Libraries and Dependencies

Android Studio modules can include external dependencies via dependencies { }. Common dependency types include:

  • AndroidX libraries
  • Third-party SDKs (Retrofit, Glide, Firebase)
  • Local .jar or .aar libraries stored in libs/

Example:

implementation 'com.squareup.retrofit2:retrofit:2.9.0'

Gradle resolves these libraries during the build process.

Build Outputs

After a successful build, Android Studio generates artifacts under:

app/build/outputs/

Common outputs:

  • apk/ – Application packages
  • bundle/ – Android App Bundles (AAB)
  • reports/ – Test and lint reports

These outputs are used for installation, testing, release, and distribution.

Visited 5 times, 2 visit(s) today
Close