The Android Studio App file structure

Application Folder structure

Summary

  1. Introduction
  2. Manifests Folder
  3. Java Folder
  4. Res Folder
  5. Gradle Scripts Folder
  6. Conclusion

Introduction

In order to create Android apps, one of the mostly used tools by developers to do this, is Android Studio. Android Studio is the official IDE (Integrated Development Environment) developed by the JetBrains community and is freely provided by Google for android app development.

After downloading and installing Android Studio, we create an android application project. For every project (application) created, Android Studio automatically creates different folders which form an application file structure to easily organize your app modules and files. It looks like this:

Application Folder structure

The project pane, is easily toggled on and off by clicking the project pane switcher. The android project contains different types of app modules, source code files, and resource files. Let us explore all the folders and files in the android application:

  1. Manifests Folder
  2. Java Folder
  3. Res Folder
    • Drawable Folder
    • Layout Folder
    • Mipmap Folder
    • Values Folder
  4. Gradle Scripts Folder

The android application structure in android studio

Manifests Folder

Every project in Android includes a manifest file, which is AndroidManifest.xml, stored in the root directory. The manifest file is an important part of our app because it defines the structure and metadata of our application, its components and requirements. Using this file, one can customize the app theme, specify the app package and all activities that are to interact with the user.

This file includes nodes for each of the Activities, Services, Content Providers and Broadcast Receiver that make the application. A typical AndroidManifest.xml file looks like:


<?xml version="1.0" encoding="utf-8">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.codtronic.tipcalculator">

    <application android:allowbackup="true" android:dataextractionrules="@xml/data_extraction_rules" android:fullbackupcontent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundicon="@mipmap/ic_launcher_round" android:supportsrtl="true" android:theme="@style/Theme.TipCalculator" tools:targetapi="31">
        <activity android:name=".MainActivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"></action>

                <category android:name="android.intent.category.LAUNCHER"></category>
            </intent-filter>
        </activity>
    </application>

</manifest>

Java Folder

The Java folder contains the Java (.java) and Kotlin (.kt) source code files that we create during app development, including other Test files. If we create any new project for Java, by default the class file MainActivity.java file is create automatically under com.codtronic.tipCalculator package. This file defines the main activity of the application from which other activities can be started and run. A typical MainActivity.java file looks like:


package com.codtronic.tipcalculator;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Res Folder

This folder contains resources that are used by the application. Such resources include images, strings, colors, view dimensions, themes, layout files and other resource files. When a particular resource needs to be utilized in several places, its recommended to place it in a single location. Thus, editing takes place in a single location. The res folder contains the following resource folders:

  • Drawable: Drawables take a variety of file like Bitmap (PNG, JPEG), Nine Patch, Vector (XML), Shape, Layers, States, Levels, and Scale.
  • Layout: A layout defines the visual structure for a user interface, such as the UI for an Android application. This folder stores layout files written in XML language. You can add additional layout objects as child elements to gradually build a view hierarchy that defines your layout file. Below is a sample layout file:
    
    <?xml version="1.0" encoding="utf-8"?>
    <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnCount="2"
        android:useDefaultMargins="true"
        tools:context=".MainActivity" >
    
        <EditText
            android:id="@+id/amountEditText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_columnSpan="2"
            android:layout_row="0"
            android:ems="10"
            android:inputType="number"
            android:minHeight="48dp" />
    
        <TextView
            android:id="@+id/amountTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_columnSpan="2"
            android:layout_row="0"
            android:text="TextView"
            android:textSize="@dimen/text_size_medium" />
    
        <TextView
            android:id="@+id/percentTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="@dimen/text_size_medium" />
    
        <SeekBar
            android:id="@+id/percentSeekBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <TextView
            android:id="@+id/tipLabelTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="@dimen/text_size_medium" />
    
        <TextView
            android:id="@+id/tipTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="@dimen/text_size_medium" />
    
        <TextView
            android:id="@+id/totalLabelTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="@dimen/text_size_medium" />
    
        <TextView
            android:id="@+id/totalTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="@dimen/text_size_medium" />
    </GridLayout>
    
  • Mimmap: This folder contains app / launcher icons that show on the home screen. It contains different density type icons such as hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi, to use different icons based on the size of the device.
  • Values: This folder contains files that define data resources for the application like strings stored in the strings.xml, colors stored in the colors.xml, app dimensions stored in dimens.xml, and theme styles stored in themes.xml

Gradle Scripts Folder

Gradle means automated build system. It contains a number of files that are used to define a build configuration. In build.gradle (Project), there are build scripts. In build.gradle (Module), there are plugins. These build configurations that can be applied to all our application modules. A sample project file is shown below:


plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.codtronic.tipcalculator"
        minSdk 19
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

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

dependencies {

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*
Please fill in your comment
*
Please provide a valid name