Version: 2019.2
Gradle troubleshooting
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), configurations, Android version support, hardware features support, and permissions.

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

How Unity produces the Android Manifest

When building your app, Unity automatically generates the Android Manifest, following the steps below:

  1. Unity takes the main Android Manifest.

  2. Unity finds all 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
    (AARs and Android Libraries).

  3. Manifests from plug-ins are merged into the main Manifest using Google’s manifmerger class.

  4. Unity modifies the Manifest, automatically adding permissions, configuration options, features used, and other information to the Manifest.

Overriding the Android Manifest

Although Unity generates a correct Manifest for you, in some cases you might want direct control over its contents.

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

In this situation, Android Libraries’ Manifests are later merged into your main Manifest, and the resulting Manifest is still tweaked by Unity to make sure the configuration is correct. For full control of the Manifest, including permissions, you need to export the Project and modify the final Manifest in Android Studio. Please note that we only support launchMode - singleTask.

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 the Android Manifest Permissions page of the Android Developer documentation.

Note that if your plug-ins require a permission by declaring it in their Manifests, the permission is automatically be added to the resulting Android Manifest during the merge stage. Any Unity APIs called by the plug-ins also contribute to the permission 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 app’s user to grant permissions while the app is running, instead of when the app is first installed. App users can usually grant or deny each permission when the app needs them 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. The Android.Permission class allows you to check whether specific permissions have been granted or denied. If a permission your app relies upon has been denied, you can inform the user why you need it and ask them to approve the permission. See Requesting Permissions.

Normally, your app prompts the user to allow what Android calls “dangerous” permissions on startup. See Android’s documentation on dangerous permissions for more information. However, if you don’t want your Unity Android app to ask for permissions on startup, you can add the following to your Manifest in either the Application or Activity sections.

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

Adding this completely suppresses the permission dialog shown on startup, but you must handle runtime permissions carefully to avoid crashes. This method is only recommended for advanced Android app developers.

For further information about the Runtime Permission System and handling permissions, see the Requesting Permissions section of the Android Developer documentation.

Examining the resulting Android Manifest

To examine the final Android Manifest that Unity has generated for your app, open the Temp/StagingArea/AndroidManifest.xml file after you have built your Project but before exiting 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).


  • 2018–10–05 Page published

  • Updated functionality in 5.5

  • Added support for Android Runtime Permissions in 2018.3.

Gradle troubleshooting
Requesting Permissions
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961