Version: 2020.1
Gradle for Android
Requesting Permissions

Android Manifest

The Android Manifest is an XML file which contains important metadata about the Android app. This includes the package name, activity names, main activity (the entry point to the app), Android version support, hardware features support, permissions, and other configurations.

For more information about the Android Manifest file, see the Android Developer documentation on Android Manifests.

How Unity produces the Android Manifest

In Unity 2019.3 and newer versions, the Android GradleAn Android build system that automates several build processes. This automation means that many common build errors are less likely to occur. More info
See in Glossary
project that Unity generates has two template manifest files:

  1. LauncherManifest.xml - Located in the exported project, at root/launcher/src/main/AndroidManifest.xml. This file contains the app’s:
    • icons
    • name
    • starting activity and its Intents
    • install location
    • supported screen sizes
    • isGame setting
  2. LibraryManifest.xml - Located in the exported project at root/unityLibrary/src/main/AndroidManifest.xml. You can override this manifest with a custom_ AndroidManifest.xml_ that you add in the Plugins/Android folder. This file declares the:
    • Unity activity
    • permissions
    • theme used by the Unity activity
    • VR modes
    • VR performance
    • making the activity non-resizable (for VR)
    • setting max aspect ratio
    • reacting to configuration changes
    • orientations
    • launch modes
    • Android UI(User Interface) Allows a user to interact with your application. More info
      See in Glossary
      hardware acceleration
    • used features (like gamepad or graphics API)
    • notch support

When Unity builds your app, it automatically generates the Android manifest files, following the steps below:

  1. Unity uses LibraryManifest.xml or AndroidManifest.xml as the main manifest.
  2. It then finds all of the Android manifests of your plug-insA set of code created outside of Unity that creates functionality in Unity. There are two kinds of plug-ins you can use in Unity: Managed plug-ins (managed .NET assemblies created with tools like Visual Studio) and Native plug-ins (platform-specific native code libraries). More info
    See in Glossary
    (.aar files and Android Libraries).
  3. It uses Google’s manifmerger class to merge plug-in manifests into the main manifest.
  4. Unity modifies the manifest files in the launcher and library modules. It automatically adds permissions, configuration options, features used, and other information.

Overriding the Android manifest

Although Unity generates a correct manifest for your app, you might want direct control over its contents.

To use an Android manifest you created outside of Unity, import your Android Manifest file to the following location: Assets/Plugins/Android/AndroidManifest.xml. This overrides the default LibraryManifest.xml.

In this situation, Unity merges the manifests of your Android libraries into your main manifest, and ensures that the resulting manifest’s configuration is correct. For full control of the manifest, including permissions, you must export the Project and modify the final manifest in Android Studio.

Note: Unity only supports the [launchMode - singleTask](https://developer.android.com/guide/topics/manifest/activity-element.html#lmode) launch mode.

Permissions

Unity automatically adds the necessary permissions to the manifest based on the Android Player Settings and Unity APIs that your app calls from the script. For example:

For more information about permissions, see Android developer documentation on Android Manifest Permissions.

If your plug-ins require a permission by declaring it in their manifests, Unity automatically adds the permission to the resulting Android manifest during the merge stage. All Unity APIs that plug-ins call also contribute to the permissions list.

Runtime permissions in Android 6.0 (Marshmallow)

If your app is running on a device with Android 6.0 (Marshmallow) or later and also targets Android API level 23 or higher, your app uses the Android Runtime Permission System.

The Android Runtime Permission System asks the user to grant permissions while the app is running, instead of when they first install the app. App users can usually grant or deny each permission when the app needs it while the app is running (for example, requesting camera permission before taking a picture). This allows an app to run with limited functionality without permissions. You can use the Android.Permission class in Unity to check whether the user granted or denied specific permissions. If a permission your app needs has been denied, you can inform the user why the app needs it and ask them to approve the permission. For more information, see documentation on Requesting Permissions.

Your app normally prompts the user to allow what Android calls “dangerous” permissions on its startup. For more information, see Android developer documentation on dangerous permissions. If you don’t want your app to ask for permissions on startup, you can add the following code to your manifest, in either the Application or Activity sections:

<meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />

Note: This code suppresses the permission dialog the app shows on startup, but you must handle runtime permissions carefully to avoid crashes. This is an advanced method of dealing with runtime permissions.

For more information about the Runtime Permission System and handling permissions, see Android developer documentation on Requesting Permissions.

Examining the resulting Android manifest

To examine the final Android manifest that Unity generates for your app, open the Temp/StagingArea/AndroidManifest.xml file after you build your Project but before you close the Unity Editor.

The Manifest is stored in binary format in the output package (.apk). To check the contents of a Manifest inside an .apkThe Android Package format output by Unity. An APK is automatically deployed to your device when you select File > Build & Run. More info
See in Glossary
, you can use the Android Studio APK Analyzer, or another third-party tool such as Apktool.


  • Unity as a Library for Android added in 2019.3.NewIn20193
  • Added support for Android Runtime Permissions in 2018.3.
  • Updated functionality in 5.5
Gradle for Android
Requesting Permissions