Use Custom Manifest File and Permission in Unity

Use custom Manifest file and permission in Unity?

You are modifying the wrong AndroidManifest file. That AndroidManifest from <ProjectName>\Temp\StagingArea you are modifying is generated by unity each time you build your project.

To use a custom AndroidManifest file, you have to put your custom AndroidManifest file at <ProjectName>Assets\Plugins\Android.

1.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Apk, Copy the AndroidManifest.xml file to your <ProjectName>Assets\Plugins\Android

2.Open the copied Manifest file from <ProjectName>Assets\Plugins\Android and add your manifest.

In your particular case, add <application android:theme="Theme.Light.NoTitleBar" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false" android:isGame="true" android:banner="@drawable/app_banner"> to it. Save, Build and Run.

Unity will now use that AndroidManifest file. If you get crash or any other problem, then Unity does not want you to change that.

Unity3D how to add permissions to AndroidManifest.xml for android plugin

Figured it out. You can add an AndroidManifest.xml to assets -> plugins -> android and it will be merged with unity's. This is a bit inconvenient for an plugin, there's no good way to include it in the jar file or with a C# wrapper, especially if you have multiple android plugins that need to contribute to the file, but it got the job done for me.

How to add permissions to Unity android application?

Player Settings -> Tab (Android) -> Publishing Settings -> Check Custom Main Manifest -> Edit "AndroidManifest.xml" in Assets/Plugins/Android

Do I have to ask permission for file manipulation for my Android app in unity?

According to Unity documentation, yes you have to ask the permissions.

Here are the permissions needed for reading and writing with the manifest file markup.

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

To make the modifications in the android manifest, you need to follow these instruction on Override the Android App Manifest

Or you can request permissions during runtime, by following this Unity documentation

How to find source of a permission in Unity Android

Unity will add permissions for you on the fly during build time as mentioned by eriQue of Unity Technologies this is to prevent malfunction of code, and unexpected behaviours.

You could use a tool such as this Apk-decompiler to take a look at your new manifest, and which permissions this uses. Based on that you may look for certain functions that could trigger these permissions.

Certain functions such as isGeniune will require several permissions as it will use verification against an external server.

Alternatively you can also replace your manifest in the decompiled APK, manually change out the manifest with the one intended, and resign it. This is some more grunt work, but if proper error logging is in place it might speed up the process of tracking down the problematic functions.

Update

As I mentioned in the comments below as well. There is no real way to pinpoint functions. But a quick check list can not hurt, but will require some work

  • Are you using any external services?

A lot of external services, think of google, twitter, facebook api's and tools require additional permissions. Usually these are storage/network related, but depending on the goals of the tool / api, it could be many more.

Try building your APK with and without the tools/apis to see if there are any differences.

  • Are you using unity ads?

Unity ads makes use of 3 permissions by itself, and older versions might still even make use of 5. If you are using their ads, then you will have to take these for granted.

  • Did you disable unity statistics?

Ever looked at those fancy stats Unity seems to be able to provide? Well, unless you disabled this, you are most likely participating in this as well.

These stats require several permissions, as the phone will be analysed on a hardware level as well as seen in the provided stats.

  • Are you really using all your api/tool/assets requirements?

You might have included some api's, tools or just about any dll from an external party that may or may not include code that requires dependencies. Just as often those are not 100% sanitized, and might include permission requirements not relevant to their functionality, or to the functionality that you require.

Say, some ad service might want to access a users microphone. But as you are not using their "OMG vocal response analyses" functions, this permission is not required for you.

These permissions can either be removed manually, as I earlier described in my answer. Or through some form of automation such as the post build marked editor script.

QUESTION SPECIFIC:

RECORD_AUDIO permission makes its way into android manifest file if there is a call to Microphone library in any of script in project. It doesn't matter if the script exists in scene or not. In this specific case, if Oculus Platform SDK is imported in project (which is a store requirement) there are few scripts which uses Microphone library. So if you don't use any audio recording feature e.g voice input, just remove the following files under OculusPlatform/Scripts: MicrophoneInput.cs, IMicrophone.cs, MicrophoneInputNative.cs

Android Internet permission in Unity

Go to Edit->Project Settings -> Player. Select Android, Build Settings, Change Internet Access from Auto to Require. You don't have to do this because Unity will do for automatically when you use any network API.

Sample Image

If that's not enough for you then you can modify the Android AndroidManifest by hand.

1. Open Unity. Build your project for Android just once. Don't close it.

2. Go to your Project Directory. A new Folder called Temp will be created by Unity after step 1. Inside that Temp there is another Folder called StagingArea. Go into the StagingArea folder and copy a file called AndroidManifest.xml into another folder in your computer. Modify/Add your own custom permission like the ones in your question.

3. Now move that modified AndroidManifest.xml file to Your Project Directory->Assets->Plugins->Android. If the Plugins and the Android Folders does not exit, create them.

Enjoy!

Unity ignores android plugin manifest file leading to missing service element in its android manifest

I figured it out. The Jar file I created does not contain the manifest file (I verified that by opening the .jar file by 7zip). So Unity does not see any manifest file in the first place to be able to merge it into its own manifest file.

To fix this issue, I created an Android Archive (AAR) file instead of jar file as follows:

  1. Open the build.gradle file for the existing app module. At the top,
    you should see the following:

    apply plugin: 'com.android.application'

  2. Change the plugin assignment as shown here:

    apply plugin: 'com.android.library'

  3. Click Sync Project with Gradle Files.

Now build the module by going into 'Gradle Projects' pane (in the right) and find the related gradle module and go to Tasks > build > build. Run it by double-clicking on it. The .aar file is built now.

1) find the .aar file of this module (it is located in mylibrary\build\outputs\aar folder). I chose the release one. It was called mylibrary-release.aar. You can open it by 7zip to verify that the Android manifest file is there.

2) Copy the .aar file into Assets\Plugins\Android folder.

That's it! Unity now merges the manifest file of the module into its own manifest. You can find the resultant manifest file in Temp\StagingArea of your Unity project.

One very important thing is that make sure your <service> element contains the fully qualified name of the service class which means package name + class name :

<service android:name="com.servicelocation.zerokey.mylibrary.MyLocationService"/>

For an example of this approach, you can create an empty project in Unity and install the Google Cast Remote Display android plugin from the asset store. You can see that google has put its .aar file under Assets > Plugins > Android and this file contains:

Sample Image

and the following is the content of this manifest:

Sample Image



Related Topics



Leave a reply



Submit