Inspecting Your Manifest

A key part of the foundation for any Android application is the manifest file: AndroidManifest.xml. This will be in your app module’s src/main/ directory (the main source set) for typical Android Studio projects.

Here is where you declare what is inside your application, such as your activities. You also indicate how these pieces attach themselves to the overall Android system; for example, you indicate which activity (or activities) should appear on the device’s launcher.

When you create your application, you will get a starter manifest generated for you. For a simple application, offering a single activity and nothing else, the auto-generated manifest will require a few minor modifications, but otherwise it will be fine. Some apps will have a manifest that has 1,000+ lines. Your production Android applications probably will fall somewhere in the middle.

The Root Element

Here is the AndroidManifest.xml file from the starter project:

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

  <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.HelloWorld">
    <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>

The root <manifest> element usually does not contain too much. It will have one or more XML namespace declarations. Here, we have just one, defining the android namespace, which is used for most of the attributes that you will find in the manifest file. We will see other manifests later on that have other namespace declarations (e.g., tools), but usually there are not too many of them.

The key attribute in the <manifest> element is package. This indicates where the build tools will generate some Java code for use by your app. We will explore that generated code later in the book.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.