Android Project Structure & Build System
Understand Android project anatomy, module structures, manifest configurations, resource qualifiers, and the Gradle build system.
Module 3: Android Project Structure & Build System
Learning Objectives
By the end of this module, you’ll understand:
- What happens when you create a new Android project
- Every important file and folder in the project
- The purpose of Gradle
- How dependencies work
- The Android build pipeline
- APK vs AAB
- Resources and the
Rclass - Build variants and product flavors
- The manifest merging process
- How Android Studio turns your code into an installable app
1. Creating a New Android Project
When you click:
File
↓
New Project
Android Studio generates much more than a simple folder of Kotlin files.
A typical project looks like:
MyApplication/
│
├── .gradle/
├── .idea/
├── gradle/
│
├── app/
│ ├── src/
│ ├── build/
│ ├── build.gradle.kts
│ └── proguard-rules.pro
│
├── build.gradle.kts
├── settings.gradle.kts
├── gradle.properties
├── gradlew
├── gradlew.bat
└── local.properties
At first glance this looks overwhelming.
The good news is:
As an Android developer, you’ll spend 95% of your time inside just a few of these directories.
2. Understanding the Project Structure
Let’s separate the project into logical parts.
Project
│
├── Source Code
├── Resources
├── Build Configuration
├── Dependencies
└── Generated Files
Each serves a completely different purpose.
3. The app Module
This is the heart of your application.
app/
│
├── src/
├── build.gradle.kts
├── build/
└── proguard-rules.pro
Think of it as:
Everything required to build one Android application.
Large projects may contain multiple modules:
app
core
network
database
feature-home
feature-profile
analytics
Each module compiles independently.
Google recommends modularization for large codebases because it improves build times and enforces better separation of concerns.
4. The src Directory
This contains your application’s source.
src/
main/
java/
res/
AndroidManifest.xml
Everything else ultimately revolves around these three items.
java/ (or kotlin/)
Despite the name, Kotlin files are stored here too.
Example:
java/
com/example/app/
MainActivity.kt
LoginActivity.kt
UserRepository.kt
ApiService.kt
This is where:
- Activities
- Fragments
- ViewModels
- Services
- Business logic
- Repositories
- Utilities
all live.
res/
Resources are not code.
Instead they are assets the Android framework manages.
res/
drawable/
layout/
values/
mipmap/
font/
anim/
menu/
xml/
raw/
color/
We’ll examine each.
5. Resource Types
Drawable
Contains images.
drawable/
logo.png
background.xml
shape.xml
A drawable may be:
- PNG
- JPG
- Vector
- XML Shape
- Selector
- Ripple
So “drawable” means anything drawable, not just images.
Layout
Contains XML layouts.
activity_main.xml
fragment_home.xml
item_user.xml
If you’re using Jetpack Compose, this folder becomes much smaller, but it still exists because many Android features rely on XML resources.
Values
Probably the most important resource folder.
values/
strings.xml
colors.xml
themes.xml
styles.xml
dimens.xml
Example:
<string name="app_name">
Android Course
</string>
Instead of:
textView.text = "Android Course"
you write:
textView.text = getString(R.string.app_name)
This allows:
- Localization
- Reusability
- Easier maintenance
Mipmap
Launcher icons.
Android treats launcher icons differently because they may need different resolutions and adaptive icon handling.
Raw
Store arbitrary files.
Examples:
music.mp3
sample.json
video.mp4
Accessed via:
resources.openRawResource(...)
XML
Configuration files.
Examples:
backup_rules.xml
network_security_config.xml
preferences.xml
6. AndroidManifest.xml
The manifest is one of the most critical files in your project.
Think of it as your app’s identity card.
Android reads it before launching your app.
Example:
<manifest>
<application>
<activity
android:name=".MainActivity"/>
</application>
</manifest>
The manifest tells Android:
- What your package name is
- Which Activity starts first
- What permissions your app needs
- What Services exist
- What BroadcastReceivers exist
- Which ContentProviders exist
- Minimum SDK
- App theme
- Backup rules
Without a valid manifest, Android cannot install your app.
7. Gradle
This deserves special attention.
Many beginners think:
Gradle is just where dependencies go.
No.
Gradle is the build system.
Think of it like a factory manager.
Developer writes code
↓
Gradle
↓
Compiles code
↓
Processes resources
↓
Downloads libraries
↓
Packages APK
↓
Signs APK
↓
Outputs app
Every time you press:
Run ▶
Gradle orchestrates the entire process.
8. Project-Level vs Module-Level Gradle
You usually see two Gradle build files.
Project
build.gradle.kts
↓
app/
build.gradle.kts
Project Level
Configures the entire project.
Examples:
- Plugin versions
- Repositories
- Shared settings
Module Level
Configures one module.
Example:
android {
namespace = "com.example.app"
compileSdk = 36
}
and:
dependencies {
}
Most day-to-day changes happen here.
9. Dependencies
Instead of writing everything yourself, you import libraries.
Example:
implementation("androidx.core:core-ktx:1.x.x")
Gradle:
Reads dependency
↓
Downloads library
↓
Caches it
↓
Adds it to compilation
Popular dependencies include:
- Retrofit
- Room
- Hilt
- Coil
- Jetpack Compose
- Navigation
10. What Happens When You Click “Run”?
This is the complete pipeline.
Kotlin Source
│
▼
Kotlin Compiler
│
▼
Bytecode (.class)
│
▼
D8
│
▼
DEX
│
▼
Merge Resources
│
▼
Generate R class
│
▼
Package APK
│
▼
Sign APK
│
▼
Install on Device
│
▼
Launch App
Each stage is performed automatically by Gradle.
11. Resource Compilation
Suppose you create:
res/drawable/logo.png
Android generates:
R.drawable.logo
Similarly,
strings.xml
becomes:
R.string.app_name
This is why you never type resource IDs manually.
12. The R Class
Many beginners think R is magic.
It’s actually a generated class.
Example:
res/
drawable/logo.png
↓
Generated
↓
R.drawable.logo
Likewise:
activity_main.xml
↓
R.layout.activity_main
When you rename or delete a resource, the R class is regenerated automatically.
13. Build Types
Android supports different builds.
debug
release
Debug:
- Logging enabled
- Debugger attached
- Faster builds
- Not optimized
Release:
- Optimized
- Signed
- Minified (optional)
- Published to users
14. Product Flavors
Large companies often build multiple versions from one codebase.
Example:
free
premium
or
India
Europe
USA
Gradle combines flavors with build types.
freeDebug
freeRelease
premiumDebug
premiumRelease
Each variant can have different:
- App name
- Icons
- API endpoints
- Features
- Resources
15. APK vs AAB
APK
Android Package
Install directly
Contains:
- Code
- Resources
- Manifest
- Native libraries
- Assets
Traditionally, APKs were uploaded to the Play Store.
AAB (Android App Bundle)
Google’s recommended publishing format.
Developer uploads
↓
Play Store
↓
Google builds optimized APK
↓
User downloads only what they need
Advantages:
- Smaller downloads
- Device-specific resources
- Language-specific resources
- ABI-specific native libraries
That’s why most Play Store apps are now published as AABs.
16. Manifest Merging
Modern Android projects often include many libraries.
Each library may provide its own AndroidManifest.xml.
During the build, Gradle merges them into a single manifest.
App Manifest
+
Library Manifest
+
Firebase Manifest
+
Navigation Manifest
↓
Merged Manifest
If there are conflicting declarations, you’ll see manifest merge errors, and Android Studio provides a merged manifest viewer to inspect the result.
17. Generated Files
Never edit generated files manually.
Examples:
build/
generated/
intermediates/
R.java
If something seems wrong, fix the source (resources, Gradle, or code), not the generated output.
18. Android Studio vs Gradle
A common misconception is that Android Studio builds your app.
In reality:
Android Studio
│
▼
User Interface (IDE)
│
▼
Gradle
│
▼
Build Process
You can even build your app without Android Studio by running Gradle from the command line.
Key Takeaways
- The
appmodule contains everything needed to build your Android application. src/mainis where your Kotlin code, resources, and manifest live.- The
resdirectory stores non-code assets like layouts, strings, images, and themes. AndroidManifest.xmldeclares your app’s components, permissions, and configuration.- Gradle is the build system responsible for compiling code, processing resources, packaging, and signing your app.
- The
Rclass is generated from your resources and provides type-safe access to them. - Build types (
debug,release) and product flavors let you create multiple app variants from the same codebase. - Android App Bundles (
.aab) are the preferred publishing format because they enable optimized, device-specific APK delivery.
Interview Questions
- What is the difference between the project-level and module-level Gradle files?
- What is the purpose of the
AndroidManifest.xml? - Explain the complete Android build pipeline from Kotlin source to an installable app.
- How is the
Rclass generated, and why is it important? - What’s the difference between
implementationandapidependencies? (We’ll cover this in more depth when discussing Gradle.) - What are build types and product flavors? Give a real-world example.
- Why has Google shifted from APK uploads to Android App Bundles (AAB)?
- Why shouldn’t you edit files inside the
build/directory?
Coming Next: Module 4 – Android App Components
This is where Android starts to feel truly unique. We’ll explore the four fundamental application components—Activities, Fragments, Services, Broadcast Receivers, and Content Providers—not just what they are, but why Android introduced them, how the system communicates with them, how processes and tasks are involved, and how these components collaborate to form a complete application. Understanding this module is essential because nearly every Android app is built from these building blocks.