Understanding the Android Manifest File

Understanding the Android Manifest File Understanding the Android Manifest File

Introduction: When you start building an Android app, you will find a special file located in your project root called AndroidManifest.xml. If this file is missing, your app cannot build or run. Today, we will explore what this configuration file does, why it is so important, and how to read it using simple words.

The Analogy: The App's Passport

Imagine your app wants to travel inside the Android operating system. When the user clicks install, the Android system acts like a **customs officer**. Before letting the app in, the officer checks the app's **Passport** (the Android Manifest) to ask:

  • Who are you? (Package Name): What is your unique ID name?
  • What screens do you have? (Activities): Let me see a list of all your rooms so I can navigate them.
  • What permissions do you want? (Permissions): Do you need to use the camera, track the user's location, or connect to the internet?
  • Where do we start? (Launcher): Which screen should I open first when the user clicks your icon?

Anatomy of an Android Manifest File

The manifest is written in **XML** format. Let's look at a simple, complete example of a manifest file:

xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.simpleapp">
    
    // 1. Request internet permission from the user
    <uses-permission android:name="android.permission.INTERNET" />
    
    <application
        android:icon="@mipmap/ic_launcher"
        android:label="My Simple App"
        android:theme="@style/Theme.AppCompat">
        
        // 2. Declare the launcher Activity (The entrance screen)
        <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>
        
        // 3. Declare a second screen (Detail screen)
        <activity android:name=".DetailActivity" />
        
    </application>
</manifest>

Understanding the Main Tags

Here is a breakdown of what each of these XML tags does inside your app:

XML TagWhat it doesExample
The main wrapper containing the app package name.package="com.example.app"
Requests system features to protect user safety.android.permission.CAMERA
Defines global settings like app icon, title name, and theme style.android:icon="@drawable/logo"
Declares a view screen. Every activity must have this tag.android:name=".SettingsActivity"
Configures how a screen can be launched (like the opening launcher).android.intent.action.MAIN
The ActivityNotFoundException Crash: If you write Kotlin code to open a new screen (Activity), but you forgot to declare that Activity inside your AndroidManifest.xml, your app will crash instantly with this exception. Android does not trust views that are not declared in the manifest!

Summary

The Android Manifest (AndroidManifest.xml) is your app's ID card. It tells the Android OS about your app's package name, requested permissions (internet, camera), application configuration (icons, themes), and lists all screens. Make sure to register every Activity in the manifest to prevent app crashes!

 All Articles
Share: