Android Project Structure (Java)

Android Studio organizes your app into modules and folders so code, resources, and build settings stay clean. This page explains each part so you always know where to add files and why they matter.

Bird’s-Eye View

Project Root

settings.gradle, build.gradle (Project), gradle.properties

app/ Module

Your Android application code and resources

manifests/

AndroidManifest.xml (activities, permissions)

java/

Java/Kotlin source (Activities, helpers)

res/

Layouts, values, drawables, mipmaps, etc.

Gradle (Module)

app/build.gradle dependencies & buildTypes

Quick Tree

# Important paths you will use most of the time
HelloAndroid/
  settings.gradle
  build.gradle        // Project-level
  gradle.properties
  app/
    build.gradle      // Module-level
    src/
      main/
        AndroidManifest.xml
        java/com/example/helloandroid/MainActivity.java
        res/
          layout/activity_main.xml
          values/strings.xml, colors.xml, styles.xml
          drawable/ (shapes, vectors), mipmap-*/ (app icons)
          xml/ (config XMLs, e.g., file_paths.xml)
      androidTest/      // UI tests
      test/             // Unit tests

Project-Level Files

FilePurpose
settings.gradle Lists included modules. Most projects start with :app.
build.gradle (Project) Global build setup (Gradle plugin version, repositories for all modules).
gradle.properties Global build flags and JVM options (e.g., org.gradle.jvmargs).
// settings.gradle
include ':app'

// build.gradle (Project)
buildscript {
  repositories { google(); mavenCentral() }
  dependencies {
    classpath 'com.android.tools.build:gradle:8.4.1'
  }
}

Module: app/

The app module contains everything that gets packaged into your APK/AAB.

app/build.gradle (Module)

plugins { id 'com.android.application' }

android {
  namespace "com.example.helloandroid"
  compileSdk 34

  defaultConfig {
    applicationId "com.example.helloandroid"
    minSdk 21
    targetSdk 34
    versionCode 1
    versionName "1.0"
  }

  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
  implementation 'androidx.appcompat:appcompat:1.7.0'
  implementation 'com.google.android.material:material:1.12.0'
}
Tip: If you add a library and get “class not found”, ensure you added it to app/build.gradle (module) and synced Gradle.

src/main/AndroidManifest.xml

Declares app components (Activities/Services), permissions, and metadata. It also marks your launcher activity.

src/main/java/

Source code in package folders (e.g., com.example.helloandroid). Typical structure:

  • ui (activities/fragments/adapters)
  • data (repositories, models, DB)
  • network (API interfaces)
  • util (helpers)

src/main/res/ (Resources)

FolderUseExamples
layout/ UI screens in XML activity_main.xml, item_row.xml
values/ Strings, colors, styles, dimens strings.xml, colors.xml, styles.xml
drawable/ Images & shapes (png/xml/vector) bg_button.xml, ic_logo.xml
mipmap-*/ App launcher icons (various densities) mipmap-xxxhdpi/ic_launcher.png
xml/ Config XMLs file_paths.xml, backup_rules.xml
menu/ Toolbar/overflow menus main_menu.xml
anim/, animator/ View and property animations fade_in.xml
font/ Font resources poppins_regular.ttf

Assets & Raw

  • src/main/assets/: arbitrary files you read with AssetManager (e.g., HTML, JSON).
  • src/main/res/raw/: raw resources accessed via R.raw.file_name (e.g., audio, SQL).

How R Class Works

Android generates R.java so you can reference resources in type-safe ways: R.layout.activity_main, R.id.btnClick, R.string.app_name. Names come from file names and android:id attributes.

// Example usage in Activity
TextView tv = findViewById(R.id.tvMessage);
setContentView(R.layout.activity_main);
setTitle(R.string.app_name);
Note: If R is red or not found, try Build → Rebuild Project, fix XML errors, or ensure resource names are lowercase with underscores.

Build Variants (debug/release) & Flavors

You can override code/resources per build type or flavor.

# Example folders
app/src/debug/AndroidManifest.xml
app/src/release/AndroidManifest.xml
app/src/free/res/values/strings.xml
app/src/pro/res/values/strings.xml
// app/build.gradle (flavor example)
android {
  flavorDimensions "tier"
  productFlavors {
    free { dimension "tier" }
    pro  { dimension "tier" }
  }
}

Density & Qualifiers

Provide alternatives for different screens/regions:

  • Density: drawable-hdpi/, -xhdpi/, -xxhdpi/
  • Language: values-hi/strings.xml
  • Night: values-night/colors.xml
  • Layout size/orientation: layout-land/, layout-sw600dp/

Where Do I Put…?

ThingFolderReference
Screen UIres/layout/R.layout.activity_main
Static textres/values/strings.xmlR.string.hello_text
Shapes/vector iconsres/drawable/R.drawable.bg_button
App iconres/mipmap-*/Configured in manifest
Fontsres/font/@font/poppins_regular
Config XMLres/xml/R.xml.file_paths
JSON/HTML to readassets/AssetManager
Audio/video rawres/raw/R.raw.beep

Common Pitfalls

  • Wrong resource name: Use only lowercase a-z, 0-9, underscore. No spaces.
  • Images in drawable too big: Prefer vectors (.xml) or multiple densities.
  • Multiple manifests: Build types/flavors can merge; check the Manifest Merger tool if conflicts arise.
  • Dependencies added to wrong Gradle file: Add libraries in app/build.gradle not project one.

Hands-On: Add a Shape Background

  1. Create res/drawable/bg_rounded_button.xml:
<!-- res/drawable/bg_rounded_button.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  <solid android:color="@color/purple_500"/>
  <corners android:radius=8dp"/>
  <padding android:left="12dp" android:top="8dp"
           android:right="12dp" android:bottom="8dp"/>
</shape>
  1. Apply in activity_main.xml Button: android:background="@drawable/bg_rounded_button"
  2. Run the app and see the styled button.

Troubleshooting

Resource not found? Check folder and name (lowercase). Rebuild project.

Duplicate resources? Look for same name in debug/, release/, or flavor folders; Gradle merges them.

Manifest errors? Use Build → Analyze APK or the Merged Manifest view to inspect final output.

Tip: Keep package structure meaningful (e.g., ui/, data/, network/). It’s easier to navigate as the app grows.