Android Project Structure
Android Project Structure
When Android Studio generates a new project it creates a specific directory layout that every Android developer must understand. The layout is not arbitrary — each folder maps to a concept in the build pipeline. Knowing where things live and why tells you where to make changes and what happens when you do.
The Top-Level View
At the root of the project you will see two distinct layers: the project level and the app module level. Android projects are multi-module by default (even if your app only has one module). The outermost build.gradle and settings.gradle files belong to the project layer; the app/ directory is your actual application module.
The Java Source Tree
All of your application code lives under app/src/main/java/ in a standard Java package hierarchy. Android Studio creates a default package based on the Application ID you entered when creating the project (e.g. com.example.myapp). Every Activity, Fragment, Service, BroadcastReceiver, and helper class you write goes here.
applicationId in build.gradle are independent, but keeping them the same avoids confusion. The Application ID is what uniquely identifies your app on the Play Store and on-device; you cannot change it after publishing.
The res/ Directory
Android separates code from resources. Everything visual or configurable — layouts, images, colours, strings — lives under res/ in type-named subdirectories. The build system compiles each resource into a numeric ID and generates the R class so your Java code can reference resources by name at compile time.
res/layout/— XML files that describe the view hierarchy of each screen or fragment.res/values/— XML files for named scalars:strings.xml,colors.xml,dimens.xml,styles.xml.res/drawable/— Vector drawables and other graphics (PNG, XML shape files).res/mipmap-*/— Launcher icons at various densities (hdpi, xhdpi, xxhdpi …).res/menu/— XML menu definitions for options menus and context menus.res/anim/— Tween animation XML files.
Accessing a string resource from Java looks like this:
res/values/strings.xml and reference them via R.string.*. This is the foundation of localisation — adding res/values-ar/strings.xml for Arabic is all it takes to support a new language.
AndroidManifest.xml
The AndroidManifest.xml at app/src/main/AndroidManifest.xml is the single most important configuration file in your project. Before the Android OS will run any component of your app, that component must be declared here. The manifest also declares:
- The application's package name (used to resolve relative class names).
- Every
<activity>,<service>,<receiver>, and<provider>in the app. - The launcher Activity — the one that starts when the user taps the icon — via an
<intent-filter>with actionMAINand categoryLAUNCHER. - Permissions the app needs from the user (
<uses-permission>). - Minimum and target SDK versions (via
<uses-sdk>, though these days they are typically set in Gradle).
<intent-filter> must set android:exported="true" or "false". Omitting it causes the build to fail. The launcher activity is always exported="true"; internal activities that only your app starts should be exported="false".
The Gradle Build System
Android uses Gradle as its build tool. There are two build scripts you must understand: the project-level script and the module-level script.
Project-level build.gradle — declares which Gradle plugins are available to all modules. You rarely edit this file beyond adding a new plugin to the classpath.
Module-level app/build.gradle — this is where you spend most of your time. It controls the Android SDK versions, signing config, and every library dependency your app uses.
Key settings to understand:
- compileSdk — the SDK version the compiler uses. Set to the latest stable release so you can use new APIs at compile time (with runtime checks for older devices).
- minSdk — the oldest Android version your app will run on. Lowering it increases your potential audience but restricts the APIs you can call unconditionally.
- targetSdk — tells Android which behaviour model your app expects. As you raise it you opt into new system behaviours (e.g. scoped storage, notification permissions). Google Play requires apps to target a recent SDK.
- applicationId — the unique identifier for your app on the Play Store. Once published, this cannot change.
implementation means the library is available to your module but not exposed to other modules that depend on yours — the right choice for almost every dependency. testImplementation adds a library only for JVM unit tests; androidTestImplementation only for instrumented (on-device) tests. Keep test libraries out of the main classpath.
settings.gradle
The settings.gradle file at the project root tells Gradle which modules exist. For a single-module app it simply contains:
When you add a library module or a feature module to your project, you add another include ':moduleName' line here and create the corresponding directory.
Summary
The Android project structure is a deliberate separation of concerns: Java sources compile your logic, res/ externalises everything that varies by locale or screen density, AndroidManifest.xml registers your components with the OS, and the Gradle scripts wire it all together into an APK or AAB. In the next lesson you will create an Activity and attach a layout, putting these folders to direct use.