What is Android App Manifest File:Use & Structure

Welcome to Android Programming tutorial. In this tutorial, I am going to teach you and describe you what a manifest file is and what it is used for and furthermore would elaborate on its structure.

What is the Android manifest file?

Every Android Application that is created includes a manifest file, which is AndroidManifest.xml, saved in the root directory of its project hierarchy. The manifest file is an important part of our app because it defines the structure and metadata of our application, its components, and its requirements.

how manifest file works
how manifest file works

According to Google’s official documentation:

Every app project must have a fileAndroidManifest.xml (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.

Other utilities of Android manifest file

  • It names the Java package for the application. The package name serves as a unique identifier for the application.
  • It describes the components of the application, which include the activities, services, broadcast receivers, and content providers that compose the application. It also names the classes that implement each of the components and publishes their capabilities, such as the messagesIntent that they can handle. These declarations inform the Android system of the components and the conditions in which they can be launched.
  • It determines the processes that host the application components.
  • It declares the permissions that the application must have in order to access protected parts of the API and interact with other applications. It also declares the permissions that others are required to have in order to interact with the application’s components.
  • It lists the classesInstrumentation that provide profiling and other information as the application runs. These declarations are present in the manifest only while the application is being developed and are removed before the application is published.
  • It declares the minimum level of the Android API that the application requires.
  • It lists the libraries that the application must be linked against.

The snippet of AndroidManifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp"
    android:versionCode="1"
    android:versionName="1.0" >
    ...
</manifest>

Manifest file elements references

Note:- To know more about these references click on the reference tag to get redirected to Google’s official documentation

<action>Adds an action to an intent filter.
<activity>Declares an activity component.
<activity-alias>Declares an alias for an activity.
<application>The declaration of the application.
<category>Adds a category name to an intent filter.
<compatible-screens>Specifies each screen configuration with which the application is compatible.
<data>Adds a data specification to an intent filter.
<grant-uri-permission>Specifies the subsets of app data that the parent content provider has permission to access.
<instrumentation>Declares an Instrumentation class that enables you to monitor an application’s interaction with the system.
<intent-filter>Specifies the types of intents that an activity, service, or broadcast receiver can respond to.
<manifest>The root element of the AndroidManifest.xml file.
<meta-data>A name-value pair for an item of additional, arbitrary data that can be supplied to the parent component.
<path-permission>Defines the path and required permissions for a specific subset of data within a content provider.
<permission>Declares a security permission that can be used to limit access to specific components or features of this or other applications.
<permission-group>Declares a name for a logical grouping of related permissions.
<permission-tree>Declares the base name for a tree of permissions.
<provider>Declares a content provider component.
<receiver>Declares a broadcast receiver component.
<service>Declares a service component.
<supports-gl-texture>Declares a single GL texture compression format that the app supports.
<supports-screens>Declares the screen sizes your app supports and enables screen compatibility mode for screens larger than what your app supports.
<uses-configuration>Indicates specific input features the application requires.
<uses-feature>Declares a single hardware or software feature that is used by the application.
<uses-library>Specifies a shared library that the application must be linked against.
<uses-permission>Specifies a system permission that the user must grant in order for the app to operate correctly.
<uses-permission-sdk-23>Specifies that an app wants particular permission, but only if the app is installed on a device running Android 6.0 (API level 23) or higher.
<uses-sdk>Lets you express an application’s compatibility with one or more versions of the Android platform, by means of an API level integer.

 

Example of one complete AndroidManifest File

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="1"
    android:versionName="1.0"
    package="com.example.myapp">

    <!-- Beware that these values are overridden by the build.gradle file -->
    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="26" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

             based upon the package attribute -->
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".DisplayMessageActivity"
            android:parentActivityName=".MainActivity" />
    </application>
</manifest>

 

Related Stories