Android Project Structure

Navigate manifest, source code, resources, Gradle scripts, and assets like a pro

Manifest Kotlin res/ Gradle

Table of Contents

Folder Tree Overview

A standard Android app module lives under app/src/main/. Source code, UI resources, and the manifest are separated so Gradle can compile, package, and optimize each part independently.

Typical app module structureMyFirstApp/ ├── app/ │ ├── src/ │ │ ├── main/ │ │ │ ├── AndroidManifest.xml │ │ │ ├── java/com/example/myfirstapp/ │ │ │ │ └── MainActivity.kt │ │ │ ├── res/ │ │ │ │ ├── drawable/ │ │ │ │ ├── layout/ │ │ │ │ ├── mipmap/ │ │ │ │ └── values/ │ │ │ └── assets/ │ │ ├── test/ # Unit tests │ │ └── androidTest/ # Instrumentation tests │ └── build.gradle.kts ├── gradle/ ├── build.gradle.kts ├── settings.gradle.kts └── gradle.properties

1Manifest File

AndroidManifest.xml is the app's blueprint. It tells Android the package name, permissions, and every component (Activities, Services, etc.) in your app.

XML — app/src/main/AndroidManifest.xml<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myfirstapp"> <uses-permission android:name="android.permission.INTERNET" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyFirstApp"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
Element / AttributePurpose
<manifest package="...">Unique app ID (used on Play Store and for intents)
<uses-permission>Declares permissions (camera, internet, location, etc.)
<application>Global app settings — icon, theme, label, backup
<activity>Registers each screen; launcher Activity has MAIN + LAUNCHER intent filter
android:exportedWhether other apps can launch this component (required for Android 12+)
Merged manifest

Libraries (Firebase, Play Services) contribute their own manifest entries. Android Studio merges them into one final manifest at build time — view the result via Build → Analyze APK or the Merged Manifest tab.

2Java/Kotlin Folder

All application logic lives under app/src/main/java/ (or kotlin/ in older templates — modern projects use java/ even for Kotlin files). The folder path mirrors your package name.

Source path exampleapp/src/main/java/com/example/myfirstapp/ ├── MainActivity.kt ├── SecondActivity.kt ├── ui/ │ └── HomeFragment.kt ├── data/ │ └── UserRepository.kt └── utils/ └── NetworkHelper.kt
Activities

Screen controllers — e.g., MainActivity.kt handles UI events and lifecycle.

Fragments

Reusable UI portions inside Activities — often in a ui/ subpackage.

Data layer

Repositories, models, API clients — keep business logic separate from UI.

Utilities

Helper classes, extensions, constants — shared code used across the app.

Kotlin — package declaration matches folder pathpackage com.example.myfirstapp import android.os.Bundle import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } }

3res Folder

The res/ (resources) folder holds all non-code assets that Android compiles into the R class. Each subfolder has a specific resource type.

SubfolderContainsReference in code/XML
drawable/Images, shapes, vector icons, selectors@drawable/ic_logo
layout/XML UI definitions@layout/activity_main
values/Strings, colors, dimensions, themes, styles@string/app_name
mipmap/Launcher icons (adaptive icons)@mipmap/ic_launcher
menu/Options menu and context menu XML@menu/main_menu
xml/Preferences, network security config@xml/network_config
Code references R.drawable.logo or @string/title
Android builds R.java / R.kt with integer IDs
Gradle compiles res/ XML and images at build time
Device locale & density pick best match (values-es, drawable-hdpi)
APK packages compiled resources for runtime
Qualifiers: Folders can include qualifiers like layout-land (landscape), values-night (dark theme), drawable-xxhdpi (high-density screens). Android picks the best match automatically.

4drawable

res/drawable/ stores graphics and XML drawables — bitmaps (PNG, WebP), vector icons (SVG converted to Vector Drawable), shapes, and state selectors.

Common drawable types

Vector Drawable

Scalable XML icons — one file for all screen densities.

Bitmap (PNG/WebP)

Photos and complex images — use WebP for smaller APK size.

Shape Drawable

Rounded corners, borders, solid fills defined in XML.

State List

Different appearance for pressed, focused, disabled states.

XML — res/drawable/rounded_button.xml<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#3DDC84" /> <corners android:radius="12dp" /> <padding android:left="16dp" android:top="8dp" android:right="16dp" android:bottom="8dp" /> </shape>
Kotlin — Use drawable in code or XML// In layout XML: // android:background="@drawable/rounded_button" // In Kotlin: imageView.setImageResource(R.drawable.ic_logo)

5layout

res/layout/ contains XML files that define UI hierarchies. Each file describes one screen or reusable UI chunk (e.g., a list item).

XML — res/layout/activity_main.xml<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tvTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name" android:textSize="22sp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="32dp" /> </androidx.constraintlayout.widget.ConstraintLayout>
Naming conventionExampleUsed for
activity_*.xmlactivity_main.xmlFull Activity screens
fragment_*.xmlfragment_home.xmlFragment UIs
item_*.xmlitem_user_row.xmlRecyclerView list rows
dialog_*.xmldialog_confirm.xmlCustom dialog layouts

6values

res/values/ centralizes strings, colors, dimensions, and themes. Externalizing these makes localization, dark mode, and design consistency much easier.

XML — res/values/strings.xml<resources> <string name="app_name">MyFirstApp</string> <string name="welcome_message">Welcome to Android!</string> <string name="button_submit">Submit</string> </resources>
XML — res/values/colors.xml<resources> <color name="primary_green">#3DDC84</color> <color name="dark_background">#061620</color> <color name="text_primary">#1A2E24</color> </resources>
XML — res/values/themes.xml<resources> <style name="Theme.MyFirstApp" parent="Theme.Material3.Light.NoActionBar"> <item name="colorPrimary">@color/primary_green</item> <item name="colorOnPrimary">@color/dark_background</item> </style> </resources>
strings.xml

All user-visible text — enables translation via values-es/, values-hi/.

colors.xml

Brand palette — reference as @color/primary_green everywhere.

dimens.xml

Spacing and sizes — 16dp margins, 14sp text sizes.

values-night/

Override colors/themes for dark mode in a parallel folder.

7Gradle Scripts

Gradle automates building, testing, and packaging your app. Android projects use Kotlin DSL (.gradle.kts) files at the project and module level.

FileScopeKey contents
settings.gradle.ktsProject rootModule list, plugin repositories
build.gradle.kts (root)Project rootShared plugin versions (AGP, Kotlin)
app/build.gradle.ktsApp moduleapplicationId, SDK versions, dependencies
gradle.propertiesProject rootJVM args, AndroidX flags, signing hints
local.propertiesLocal only (gitignored)sdk.dir path to Android SDK
gradle/libs.versions.tomlVersion catalogCentralized dependency versions (optional)
Kotlin DSL — app/build.gradle.ktsplugins { id("com.android.application") id("org.jetbrains.kotlin.android") } android { namespace = "com.example.myfirstapp" compileSdk = 34 defaultConfig { applicationId = "com.example.myfirstapp" minSdk = 24 targetSdk = 34 versionCode = 1 versionName = "1.0" } buildTypes { release { isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) } } } dependencies { implementation("androidx.core:core-ktx:1.12.0") implementation("androidx.appcompat:appcompat:1.6.1") implementation("com.google.android.material:material:1.11.0") }
Gradle — Common tasks# Sync and build debug APK ./gradlew assembleDebug # Run all unit tests ./gradlew test # List project dependencies ./gradlew app:dependencies

8Assets & Resources

Android distinguishes between resources (res/) and raw assets (assets/). Understanding the difference prevents common packaging and access errors.

Featureres/ (Resources)assets/ (Raw Assets)
Access viaR.drawable.logo or @string/titleAssetManager.open("file.json")
Compiled?Yes — IDs generated in R classNo — stored as-is in APK
SubfoldersFixed types (drawable, layout, values)Any folder structure you create
LocalizationAutomatic via qualifiersManual — you handle locales in code
Typical useUI, strings, icons, themesJSON configs, fonts, HTML, ML models, game assets
Assets folder exampleapp/src/main/assets/ ├── config/ │ └── app_settings.json ├── fonts/ │ └── custom_font.ttf └── help/ └── faq.html
Kotlin — Read a file from assets/// Read JSON from assets/config/app_settings.json val json = assets.open("config/app_settings.json") .bufferedReader() .use { it.readText() } Log.d("Assets", json)
Kotlin — Read from res/raw/ (alternative)// res/raw/sample.json → R.raw.sample val inputStream = resources.openRawResource(R.raw.sample) val text = inputStream.bufferedReader().use { it.readText() }
Use res/
UI, strings, icons, themes
Use assets/
Custom files, ML models, game data
Use res/raw/
Single raw files needing an R.raw ID

Key takeaway: Use res/ when Android should compile and ID your files; use assets/ when you need raw files with custom folder paths read at runtime.

9Summary Table – Resource Access

Quick reference for how each resource type is stored and accessed in XML layouts vs Kotlin code.

Resource TypeFolderAccess in XMLAccess in Kotlin
Layoutres/layout/@layout/activity_mainR.layout.activity_main
Stringres/values/strings.xml@string/app_nameR.string.app_name
Colorres/values/colors.xml@color/purple_500R.color.purple_500
Dimensionres/values/dimens.xml@dimen/padding_smallR.dimen.padding_small
Image (png)res/drawable/@drawable/iconR.drawable.icon
Vector drawableres/drawable/@drawable/ic_heartR.drawable.ic_heart
Shape drawableres/drawable/@drawable/rounded_buttonR.drawable.rounded_button
Menures/menu/@menu/main_menuR.menu.main_menu
Animationres/anim/@anim/fade_inR.anim.fade_in
Raw fileres/raw/Not in XMLR.raw.data
Assetassets/Not in XMLassets.open("file.txt")

10Hands-On Exercises

Apply what you learned about project structure with these practical tasks.

1

Add a custom string to strings.xml and display it in a TextView in activity_main.xml using @string/your_key.

2

Create a shape drawable (rounded rectangle with gradient) in res/drawable/ and set it as the background of a button via android:background="@drawable/your_shape".

3

Add a vector asset in Android Studio: File → New → Vector Asset — choose a Material icon and reference it as @drawable/ic_your_icon.

4

Change the app launcher icon by replacing files in res/mipmap/ folders, or use Image Asset Studio (right-click res → New → Image Asset).

5

Add an asset file (e.g., sample.txt) to assets/, read it in MainActivity with assets.open("sample.txt"), and show its content in a TextView.

6

Increment versionCode and versionName in app/build.gradle.kts, then build a new APK and observe the version change in app settings.

Exercise 2 hint — gradient shape drawable

XML — res/drawable/gradient_button.xml<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#3DDC84" android:endColor="#2EB872" android:angle="90" /> <corners android:radius="16dp" /> </shape>

Exercise 5 hint — read asset in MainActivity

Kotlin — Display asset text in TextViewval assetText = assets.open("sample.txt") .bufferedReader() .use { it.readText() } findViewById<TextView>(R.id.tvAssetContent).text = assetText

11Common Errors & Solutions

These issues come up often when working with Android project structure and resources.

ErrorLikely CauseFix
Resource not found Typo in resource ID or file missing Check R.id.xxx matches XML android:id; verify file exists in correct res/ folder
ActivityNotFoundException Activity not declared in manifest Add <activity android:name=".YourActivity"> in AndroidManifest.xml
assets/ returns null Folder missing or path wrong Create app/src/main/assets/ folder; check path spelling (case-sensitive)
minifyEnabled breaks app Code removed by R8/ProGuard Add ProGuard keep rules in proguard-rules.pro, or test with isMinifyEnabled = false first
VersionCode must be increased Uploading same version code to Play Store Increment versionCode in defaultConfig for each release upload

Summary: The manifest declares your app to the system; Kotlin/Java folders hold logic; res/ powers your UI and branding; Gradle scripts orchestrate the build; and assets/ stores raw files accessed at runtime. Use the resource access table as a cheat sheet and complete the exercises to solidify your understanding.

Project Structure MCQ Practice

10 Basic MCQs 10 Advanced MCQs

10 Basic Project Structure MCQs

1

AndroidManifest.xml defines?

AGradle dependencies
BApp components and permissions
CImage drawables
DDatabase schema
Explanation: The manifest declares Activities, Services, permissions, and app metadata.
2

Kotlin/Java source typically lives in?

Ares/raw/
Bsrc/main/java or kotlin/
Cassets/
Dgradle/
Explanation: Source files go under src/main/java/ or src/main/kotlin/ mirroring package structure.
3

String resources are stored in?

Ares/values/strings.xml
BAndroidManifest.xml
Cbuild.gradle only
Dassets/text/
Explanation: Default strings live in res/values/strings.xml for localization.
4

Drawable resources folder is?

Ares/drawable/
Bsrc/drawable/
Clib/drawable/
Dmanifest/drawable/
Explanation: PNG, XML vector drawables, and shapes go in res/drawable variants.
5

R.java / R.kt is?

AHand-written config
BAuto-generated resource IDs class
CGradle plugin
DADB script
Explanation: The build generates R linking code to layout, drawable, string resources.
6

Module-level build file is usually?

Asettings.gradle.kts
Bapp/build.gradle.kts
Clocal.properties only
Dproguard.txt
Explanation: The app module's build.gradle.kts configures plugins, SDK versions, dependencies.
7

assets/ folder holds?

ARaw files accessed via AssetManager
BCompiled dex only
CManifest backup
DEmulator images
Explanation: Assets are uncompressed files read at runtime (fonts, JSON, etc.).
8

mipmap/ is typically for?

ALauncher icons
BLayout XML
CSQL databases
DGradle cache
Explanation: Launcher icons use mipmap densities (mdpi, hdpi, xhdpi, etc.).
9

colors.xml contains?

AColor resource definitions
BActivity names
CNetwork URLs
DSigning keys
Explanation: Named colors referenced as @color/primary in layouts and themes.
10

settings.gradle.kts defines?

AWhich modules belong to the project
BApp label
CADB port
DEmulator RAM
Explanation: It includes modules like include(":app").

10 Advanced Project Structure MCQs

11

res/layout-land/ provides?

ALandscape-specific layouts
BGradle scripts
CNight theme only
DDebug APK
Explanation: Qualifier folders supply alternate resources by orientation, size, or API.
12

@+id/button in XML means?

ACreate new ID resource named button
BDelete button
CImport library
DPrivate Java field
Explanation: @+id/ allocates a new ID in R.id during resource linking.
13

Why separate res/values-night/?

ADark theme color/style overrides
BFaster Gradle
CSmaller APK always
DADB config
Explanation: Night qualifiers apply resources when uiMode is night.
14

ProGuard/R8 rules often in?

Aproguard-rules.pro
Bstrings.xml
CAndroidManifest only
Dadb.ini
Explanation: proguard-rules.pro keeps classes from obfuscation/removal in release.
15

src/main/res vs src/androidTest/res?

AMain app vs instrumented test resources
BSame folder
CEmulator only
DDeprecated
Explanation: Test source sets have separate manifests and resources.
16

Gradle cache corruption symptom?

ABizarre sync errors; invalidate caches
BLayout preview only slow
CEmulator black screen always
DR.id always zero
Explanation: File → Invalidate Caches can fix stale Gradle/Android Studio state.
17

Vector drawable advantage?

AScalable single XML asset
BRequires 5 PNG sizes only
CCannot tint
DJava-only
Explanation: VectorDrawable scales without multiple bitmap densities.
18

tools: namespace attributes?

ADesign-time only; stripped at build
BRequired at runtime
CReplace manifest
DEncrypt resources
Explanation: tools:* attributes assist the editor and are not packaged.
19

Product flavors in Gradle create?

AVariant dimensions (free/paid, etc.)
BNew manifest only
CAutomatic Play listing
DEmulator snapshots
Explanation: Flavors combine with build types to form variant matrix.
20

Accessing raw JSON in assets?

Aassets.open("file.json")
BR.raw only always
Cadb pull
DManifest meta-data only
Explanation: Use AssetManager from context.assets to read asset files.
Click an option to select, then check answers.

Project Structure Interview Q&A

15 topic-focused questions for interviews and revision.

1Describe the standard Android project folder layout.easy
Answer: Project root has settings.gradle, build.gradle; app module has src/main/java|kotlin, res/, AndroidManifest.xml, and module build.gradle.kts.
2What is the purpose of AndroidManifest.xml?easy
Answer: Declares package, components, permissions, features, intent filters, and application-level attributes required by the system.
3Explain res/values, res/layout, res/drawable.easy
Answer: values: strings, colors, styles; layout: UI XML; drawable: images, vectors, shapes used by layouts and code.
4How does resource qualifiers work?medium
Answer: Folder names like layout-sw600dp or values-night select alternate resources based on device configuration at runtime.
5Difference between assets and res/raw.medium
Answer: Both hold raw files; res/raw gets a resource ID (R.raw); assets are accessed by path via AssetManager without R entries.
6What files control SDK versions?easy
Answer: app/build.gradle.kts: minSdk, targetSdk, compileSdk; sometimes gradle/libs.versions.toml in version catalogs.
7Why is R class missing or red?medium
Answer: Resource compilation failed due to XML errors, sync not done, or wrong module; fix resources and rebuild.
8Role of settings.gradle.kts in multi-module apps.medium
Answer: Includes library modules (feature, data) enabling shared code and separate build.gradle per module.
9What is stored in gradle/libs.versions.toml?medium
Answer: Version catalog centralizing dependency versions and plugin aliases for cleaner Gradle files.
10Explain mipmap vs drawable for icons.medium
Answer: Launcher icons use mipmap so OEM launchers can pick appropriate density; in-app images use drawable.
11How are themes and styles organized?medium
Answer: styles.xml and themes.xml in res/values define attributes applied to Activities or Views via @style/Theme.App.
12What is src/androidTest for?medium
Answer: Instrumented tests running on device/emulator with separate test manifest and dependencies.
13Common manifest merge conflicts?hard
Answer: Multiple libraries add permissions or components; use tools:replace or merge rules in Gradle packagingOptions.
14How do you add a new module?medium
Answer: File → New → Module; Gradle adds include in settings.gradle; app module declares implementation(project(...)).
15Security: what should never go in res/ or assets unencrypted?hard
Answer: API secrets, private keys, passwords — use backend, Android Keystore, or remote config with proper auth.