Understanding Project Structure and Application Files
Course: Android App Development
Topic: Understanding Project Structure and Application Files
Course Link: Android App Development Course
Demo Registration: Register for a Course Demo
Website: JustAcademy Official Website
1. Introduction to Android Project Structure
An Android project is a collection of source code files, application resources, configuration files, dependencies, and testing components required to develop and run an Android application. Android Studio organizes these files into folders and modules so developers can manage application functionality efficiently.
Understanding the project structure is essential for Android developers because it helps them locate Kotlin or Java source files, design user interfaces, manage application permissions, configure dependencies, and troubleshoot build errors.
When a new Android project is created, Android Studio generates a standard directory structure based on the selected project template. The exact files and folders depend on whether the project uses Jetpack Compose, XML layouts, Kotlin, Java, or additional modules.
Why Is Project Structure Important?
- Organizes application code into logical packages and modules.
- Separates source code from images, strings, and other resources.
- Defines application components and permissions.
- Manages external libraries and build configurations.
- Supports unit testing and device-based testing.
- Makes debugging, maintenance, and collaboration easier.
- Helps developers understand how an application is compiled and packaged.
2. Overview of an Android Studio Project
A typical Android application project contains a project-level configuration, one or more modules, source code, resources, test directories, and Gradle build files.
Typical Android Project Structure
MyAndroidApp/
├── .gradle/
├── .idea/
├── app/
│ ├── build/
│ ├── libs/
│ ├── src/
│ │ ├── androidTest/
│ │ ├── main/
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java/
│ │ │ │ └── com/example/myandroidapp/
│ │ │ │ └── MainActivity.kt
│ │ │ ├── res/
│ │ │ │ ├── drawable/
│ │ │ │ ├── mipmap/
│ │ │ │ ├── values/
│ │ │ │ └── xml/
│ │ │ └── assets/
│ │ └── test/
│ ├── build.gradle.kts
│ └── proguard-rules.pro
├── gradle/
│ └── wrapper/
├── build.gradle.kts
├── gradle.properties
├── gradlew
├── gradlew.bat
├── local.properties
└── settings.gradle.kts
Note: This is an illustrative structure, not a mandatory layout for every project. Some files and folders may not exist until they are needed. Android Studio may also display the project differently depending on the selected view.
3. Understanding the Project View and Android View
Android Studio provides different ways to display project files. The Android view groups files by their development purpose, while the Project view shows a structure closer to the actual file system.
| View |
Description |
When to Use |
| Android View |
Groups manifests, source code, resources, and Gradle configuration into convenient categories. |
Daily Android development and quick navigation. |
| Project View |
Shows actual directories and files, including many configuration and generated folders. |
Understanding file locations and investigating build configuration. |
| Project Files or Other Available Views |
May expose additional project-related files depending on the Android Studio version. |
Advanced inspection and troubleshooting. |
How to Open the Project Window
- Open an Android project in Android Studio.
- Select View from the main menu.
- Open Tool Windows and select Project.
- Use the view selector at the top of the Project window.
- Select Android or Project depending on the files you want to inspect.
The Android view is a convenient representation and does not always match the physical directory hierarchy exactly.
4. Understanding the App Module
The app module is the conventional default module for an Android application. It contains the application source code, resources, manifest, and module-level build configuration. A project may contain additional modules for reusable libraries or separate features.
Main Responsibilities of the App Module
- Contains the code that implements application functionality.
- Stores layouts, images, icons, strings, and other resources.
- Declares application components in the manifest.
- Defines dependencies and build settings.
- Contains test source sets for application verification.
- Produces application build outputs such as APKs or components used to create Android App Bundles.
Although app is the common name, a module can have a different name. Module names are configured as part of the project build.
5. Understanding the src Directory
The src directory contains the source sets used to build an Android module. A source set groups source files and resources for a particular purpose, such as the main application, local tests, device tests, or a specific build variant.
| Directory |
Purpose |
src/main/ |
Contains source code and resources shared by the application's build variants. |
src/test/ |
Contains local unit tests that normally run on the development computer's JVM. |
src/androidTest/ |
Contains instrumented tests that run on an Android device or emulator. |
src/debug/ |
May contain code or resources specific to the debug build type. |
src/release/ |
May contain code or resources specific to the release build type. |
Additional source sets can be created for product flavors and other build variants. Their use depends on the project's build configuration.
6. Understanding the AndroidManifest.xml File
The AndroidManifest.xml file provides essential information about an Android application to the Android build tools and operating system. It declares application metadata, components, permissions, and other configuration details.
Important Manifest Responsibilities
- Declares Activities, services, broadcast receivers, and content providers where applicable.
- Specifies permissions required by the application.
- Defines application-level properties and metadata.
- Supports component intent filters and related declarations.
- Identifies launcher behavior through the appropriate Activity and intent-filter configuration when required.
- Provides information used by Android tools to package and install the application.
Example AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MyAndroidApp">
<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>
Explanation
manifest is the root element of the manifest document.
application contains application-wide configuration.
android:label references the application's display name.
android:theme references a theme resource.
activity declares an Activity component.
android:exported="true" allows the declared component to be launched by other applications when the applicable Android rules permit it. A component with a launcher intent filter generally needs this setting on modern Android versions.
- The MAIN action and LAUNCHER category identify the entry point shown in the device launcher.
This is a simplified example. The actual manifest should match the application's components, permissions, themes, and generated project configuration.
7. Understanding Kotlin and Java Source Files
Android application logic is written primarily in Kotlin or Java. Source files are commonly stored in the module's src/main/java/ directory, although some Kotlin-only projects may use a src/main/kotlin/ directory. Both languages can coexist in the same project.
Example Kotlin File: MainActivity.kt
package com.example.myandroidapp
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Text(text = "Welcome to Android Development!")
}
}
}
Explanation of the Source File
- Package declaration: Identifies the package containing the class.
- Import statements: Make classes and functions available to the source file.
- Class declaration: Defines the Activity class.
- onCreate(): Handles initialization when the Activity is created.
- setContent: Provides the Compose content displayed by the Activity.
- Text: Displays a text element in the user interface.
This example assumes that the project includes compatible Jetpack Compose dependencies and an appropriate theme configuration. XML-based projects may use a different Activity implementation.
8. Understanding the res Directory
The res directory contains Android resources that are compiled and packaged with the application. Resources separate content and visual assets from application logic, making applications easier to maintain and localize.
| Resource Directory |
Purpose |
Example |
drawable/ |
Stores drawable resources, such as images and drawable XML definitions. |
background.xml |
mipmap/ |
Commonly stores launcher icons in different density variants. |
ic_launcher.png |
values/ |
Stores values such as strings, colors, dimensions, and styles. |
strings.xml |
layout/ |
Stores XML layout files for view-based interfaces. |
activity_main.xml |
menu/ |
Stores menu resource definitions. |
main_menu.xml |
xml/ |
Stores miscellaneous XML configuration resources. |
backup_rules.xml |
anim/ |
Can store view animation resources. |
fade_in.xml |
font/ |
Can store custom font resources. |
custom_font.ttf |
Not every project needs every resource directory. Android Studio creates or exposes resource folders according to the project template and resources added by the developer.
9. Understanding the values Directory
The res/values/ directory contains XML files that define reusable values. Storing these values centrally reduces duplication and helps keep the application consistent.
Common Values Resources
strings.xml stores user-visible text.
colors.xml stores named color values.
dimens.xml stores reusable dimensions.
themes.xml defines theme-related resources in many project templates.
styles.xml may define styles in projects using style resources.
Example strings.xml
<resources>
<string name="app_name">My Android App</string>
<string name="welcome_message">Welcome to Android Development!</string>
<string name="login_button">Login</string>
</resources>
Using a String Resource
In an XML layout, a string resource can be referenced with the @string/ notation. In Kotlin, resources can be accessed through the appropriate Android context, for example getString(R.string.welcome_message) inside a suitable Activity.
Using string resources makes localization easier because translated values can be placed in language-specific resource directories.
10. Understanding XML Layout Files
XML layout files define user-interface structures in view-based Android applications. They describe interface elements such as text views, buttons, input fields, and containers.
Example activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/txtWelcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/welcome_message"
android:textSize="22sp" />
<Button
android:id="@+id/btnContinue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Continue" />
</LinearLayout>
Important Layout Attributes
layout_width defines the width of a view.
layout_height defines the height of a view.
orientation controls the direction of a LinearLayout.
padding defines the space between a view's content and its edges.
id identifies a view for references from code and other resources.
text sets the text displayed by a text-based view.
XML layouts are used in view-based applications. Jetpack Compose applications can define their interfaces directly in Kotlin and may not need an XML layout file for every screen.
11. Understanding the assets Directory
The assets directory stores files that an application needs to access in their original file form rather than as standard named Android resources. These files are packaged with the application and can be read through Android's AssetManager.
Examples of Asset Files
- JSON files containing bundled sample data.
- HTML files used by an application WebView.
- Text files and predefined templates.
- Game resources and other application-specific data.
- Files that need to be read as streams.
Example: Reading a Text Asset
val content = assets.open("sample.txt")
.bufferedReader()
.use { reader -> reader.readText() }
This code belongs inside a suitable Android component or class with access to the application's assets. The use function closes the resource after the block completes. Ensure that sample.txt exists in the module's src/main/assets/ directory.
12. Understanding the libs Directory and Dependencies
The libs directory may be used to store local library files, such as JAR or AAR packages. Modern Android projects commonly declare external dependencies through Gradle rather than manually copying every library into the project.
Types of Dependencies
| Dependency Type |
Description |
| External Library |
A library retrieved from a configured Maven repository. |
| Local JAR |
A Java archive stored within the project and referenced by the build configuration. |
| Local AAR |
An Android library archive containing compiled code and Android resources. |
| Module Dependency |
A dependency on another module in the same project. |
Example Gradle Dependency
dependencies {
implementation("androidx.core:core-ktx:1.15.0")
}
This is an illustrative dependency declaration, not a recommendation to use that specific version in every project. Select a compatible version and verify the project's existing dependency configuration before making changes.
13. Understanding Gradle Build Files
Gradle build files describe how a project and its modules are built. Android Studio commonly uses Kotlin DSL files ending in .gradle.kts, although projects using Groovy DSL use .gradle files.
| File |
Purpose |
settings.gradle.kts |
Defines the Gradle build structure, project name, included modules, and repository management where configured. |
Root build.gradle.kts |
Contains project-level plugin declarations and shared build configuration where needed. |
Module app/build.gradle.kts |
Defines app-module plugins, Android settings, dependencies, and build options. |
gradle.properties |
Contains Gradle properties and project-level build configuration values. |
gradle/libs.versions.toml |
May define dependency and plugin versions using a version catalog. |
gradle/wrapper/gradle-wrapper.properties |
Specifies the Gradle distribution used by the Gradle Wrapper. |
Understanding Module-Level Configuration
The app module build file typically contains Android configuration, SDK levels, build types, and dependencies. Its exact structure depends on the Android Gradle Plugin version and the conventions used by the project.
Example Module Configuration
android {
namespace = "com.example.myandroidapp"
compileSdk = 35
defaultConfig {
applicationId = "com.example.myandroidapp"
minSdk = 23
targetSdk = 35
versionCode = 1
versionName = "1.0"
}
}
This configuration is an example only. Use the SDK levels and plugin versions appropriate for your project, and avoid replacing generated configuration without understanding its effect.
14. Understanding settings.gradle.kts
The settings.gradle.kts file defines the structure of a Gradle build and identifies which modules are included. It can also configure dependency repositories and other settings.
Example
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(
RepositoriesMode.FAIL_ON_PROJECT_REPOS
)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "MyAndroidApp"
include(":app")
This is a common illustrative pattern. A real project may use centralized plugin versions, additional modules, or different repository policies. Preserve the configuration generated by Android Studio unless a change is required.
15. Understanding gradle.properties and local.properties
gradle.properties
The gradle.properties file contains properties used by Gradle and the project build. Depending on the setup, it may contain build-performance options, AndroidX settings, or other configuration values.
local.properties
The local.properties file commonly stores machine-specific configuration, including the local Android SDK path. It should not normally be used to store shared project settings that need to work across different computers.
Because local.properties can contain computer-specific paths, it is commonly excluded from version control. Do not publish sensitive local configuration or credentials in a repository.
16. Understanding the Gradle Wrapper
The Gradle Wrapper allows a project to use a specified Gradle distribution without requiring every developer to install that exact Gradle version globally.
Important Wrapper Files
gradlew is the Unix-like wrapper script.
gradlew.bat is the Windows wrapper script.
gradle/wrapper/gradle-wrapper.jar contains the wrapper implementation.
gradle/wrapper/gradle-wrapper.properties specifies the Gradle distribution configuration.
The wrapper helps developers and build servers use a consistent Gradle version. Keep the wrapper files in version control so team members can reproduce the intended build environment.
17. Understanding Test Directories
Testing directories separate application code from the code used to verify its behavior. Android projects commonly support local unit tests and instrumented tests.
| Test Directory |
Execution Environment |
Typical Use |
src/test/ |
Local JVM on the development computer. |
Testing business logic, calculations, and other code that can run without a real Android environment. |
src/androidTest/ |
Android device or emulator. |
Testing UI interactions, Android framework behavior, and integration with device components. |
Example Unit Test
import org.junit.Assert.assertEquals
import org.junit.Test
class CalculatorTest {
@Test
fun addNumbers_returnsCorrectTotal() {
val result = 10 + 20
assertEquals(30, result)
}
}
This example assumes a compatible JUnit dependency is configured. Tests help identify defects early and provide confidence when application code changes.
18. Understanding Build Outputs
During compilation, Gradle generates intermediate files, compiled resources, reports, and packaged application outputs. These generated files are generally stored in build directories.
Common Build Outputs
- APK: An Android application package that can be installed on compatible Android devices.
- AAB: An Android App Bundle format commonly used for publishing through Google Play.
- Intermediate files: Generated files used during compilation and packaging.
- Test reports: Results produced by supported testing tasks.
- Build logs: Diagnostic information that helps developers investigate failed builds.
Build output directories are generated by the build system and normally should not be manually edited. They can often be regenerated by building the project again.
19. Understanding Application IDs and Namespaces
Application identifiers and namespaces are related but distinct concepts in Android projects.
| Setting |
Purpose |
applicationId |
Identifies the installed application and is used by Android distribution and package-management systems. |
namespace |
Determines the package namespace for generated code, including the generated R class. |
| Kotlin package declaration |
Organizes source code classes and controls their fully qualified names. |
These values often look similar in a simple project but do not have to be identical. Changes to an application's ID can affect installation identity, publishing, and updates, so they should be planned carefully.
20. Managing Multiple Modules
Large Android projects can be divided into modules to improve separation of responsibilities, code reuse, and build organization. Modules can represent application components, reusable libraries, or other supported features.
Examples of Modules
:app contains the primary application module.
:core may contain shared utility or foundational code.
:data may contain data sources and repository implementations.
:feature:profile may contain profile-related functionality.
:network may contain shared networking code.
These names are illustrative and are not automatically created by every Android Studio template. Modules should be introduced when they provide a clear architectural or organizational benefit.
21. Common Project Structure Mistakes
| Mistake |
Why It Is a Problem |
Recommended Solution |
| Editing generated build output |
Changes may be overwritten during the next build. |
Edit source files and build configuration instead. |
| Placing files in the wrong source set |
Code or resources may not be included in the intended build variant. |
Use the correct src/main, src/test, or src/androidTest directory. |
| Hardcoding all user-visible text |
Makes localization and content maintenance harder. |
Use string resources where appropriate. |
| Changing applicationId without planning |
Can affect installation identity and app updates. |
Understand publishing and package identity before changing it. |
| Ignoring Gradle configuration |
Can cause dependency resolution and build compatibility problems. |
Check plugin, JDK, Gradle, and SDK compatibility. |
| Committing machine-specific settings |
May create conflicts or expose local paths. |
Follow suitable version-control ignore rules. |
| Mixing unrelated functionality in one class |
Reduces readability and testability. |
Organize code into focused classes and packages. |
22. Practical Exercise: Explore an Android Project
Objective: Understand how application code, resources, configuration, and tests are organized in Android Studio.
- Create a new Kotlin-based Android project.
- Open the Project window and switch between Android and Project views.
- Locate the
app module and its module-level build file.
- Open
AndroidManifest.xml and identify the declared application components.
- Locate
MainActivity.kt or the main Kotlin source file.
- Explore the
res directory and identify available resource folders.
- Find
settings.gradle.kts and the root build file.
- Inspect the module's dependency declarations.
- Locate the local and instrumented test directories.
- Build and run the project to verify that the structure is configured correctly.
23. Mini Project: Organizing a Student Application
Objective: Create a small student application with a clear separation between application code, resources, configuration, and tests.
Suggested Structure
StudentApp/
├── app/
│ ├── src/
│ │ ├── main/
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java/com/example/studentapp/
│ │ │ │ ├── MainActivity.kt
│ │ │ │ └── Student.kt
│ │ │ └── res/
│ │ │ └── values/
│ │ │ └── strings.xml
│ │ ├── test/
│ │ └── androidTest/
│ └── build.gradle.kts
├── gradle/
├── build.gradle.kts
└── settings.gradle.kts
Suggested Features
- Display a student's name and course.
- Store reusable labels in string resources.
- Keep student-related data in an appropriate Kotlin class or data class.
- Use the manifest and generated project configuration correctly.
- Add a unit test for a simple business rule.
- Build and test the application on an emulator.
24. Interview Questions and Answers
Q1. What is an Android project?
Answer: An Android project is a workspace containing source code, resources, configuration files, dependencies, and tests needed to build and maintain an Android application.
Q2. What is the app module?
Answer: The app module is the conventional application module containing source code, resources, manifest configuration, and module-level build settings.
Q3. What is the purpose of AndroidManifest.xml?
Answer: It declares application components, permissions, metadata, and other configuration information used by Android tools and the operating system.
Q4. What is the res directory?
Answer: It stores compiled application resources such as images, strings, colors, dimensions, themes, and XML layouts.
Q5. What is the difference between Android view and Project view?
Answer: Android view organizes files by development purpose, while Project view exposes the actual directory structure more directly.
Q6. What is the purpose of Gradle build files?
Answer: Gradle build files define project modules, plugins, dependencies, SDK settings, and other build configuration.
Q7. What is the difference between test and androidTest?
Answer: The test source set normally contains local JVM tests, while androidTest contains instrumented tests that execute on an Android device or emulator.
Q8. What is the purpose of strings.xml?
Answer: It stores reusable text resources, making application content easier to maintain and translate.
Q9. What is the Gradle Wrapper?
Answer: It provides scripts and configuration that allow a project to use a specified Gradle distribution consistently.
Q10. What is the difference between applicationId and namespace?
Answer: The applicationId identifies the installed application, while the namespace determines the package namespace used for generated code and related configuration.
25. Quick Revision Checklist
- Understand the purpose of Android project structure.
- Know the difference between Android view and Project view.
- Identify the app module and source sets.
- Understand the Android manifest and application components.
- Locate Kotlin source files and resource directories.
- Understand XML layouts and Jetpack Compose files.
- Identify the purpose of assets and local libraries.
- Understand Gradle build files and dependency configuration.
- Know the purpose of the Gradle Wrapper.
- Distinguish local tests from instrumented tests.
- Understand application IDs and namespaces.
- Build and run a project after exploring its structure.
Conclusion
Understanding Android project structure and application files is an essential skill for Android developers. Each directory and configuration file has a specific responsibility, from storing Kotlin code and application resources to declaring components and managing build dependencies. Learning how these elements work together helps developers create organized, maintainable, and testable Android applications.
Explore the JustAcademy official website, learn more about the Android App Development course, or register for a course demo.