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.
According to Google’s official documentation:
Every app project must have a file
AndroidManifest.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 messages
Intentthat 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 classes
Instrumentationthat 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
|Adds an action to an intent filter.|
|Declares an activity component.|
|Declares an alias for an activity.|
|The declaration of the application.|
|Adds a category name to an intent filter.|
|Specifies each screen configuration with which the application is compatible.|
|Adds a data specification to an intent filter.|
|Specifies the subsets of app data that the parent content provider has permission to access.|
|Declares an |
|Specifies the types of intents that an activity, service, or broadcast receiver can respond to.|
|The root element of the AndroidManifest.xml file.|
|A name-value pair for an item of additional, arbitrary data that can be supplied to the parent component.|
|Defines the path and required permissions for a specific subset of data within a content provider.|
|Declares a security permission that can be used to limit access to specific components or features of this or other applications.|
|Declares a name for a logical grouping of related permissions.|
|Declares the base name for a tree of permissions.|
|Declares a content provider component.|
|Declares a broadcast receiver component.|
|Declares a service component.|
|Declares a single GL texture compression format that the app supports.|
|Declares the screen sizes your app supports and enables screen compatibility mode for screens larger than what your app supports.|
|Indicates specific input features the application requires.|
|Declares a single hardware or software feature that is used by the application.|
|Specifies a shared library that the application must be linked against.|
|Specifies a system permission that the user must grant in order for the app to operate correctly.|
|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.|
|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>