How to add a line on the manifest instead of replacing the whole of it

Hi! I just want to add this line to the manifest to not allow Google Play from doing the autobackup of my game.

<application android:allowBackup="false"  tools:replace="android:allowBackup"></application>

However according to this link Unity - Manual: Android App Manifest, making an AndroidManifest.xml will actually replace the whole manifest instead of adding those lines.

Is there any way to add that line to the manifest instead of doing a new one all by myself?

Thanks.

1 Like

I ended up by going to C:\Program Files\Unity\Hub\Editor<your unity version>\Editor\Data\PlaybackEngines\AndroidPlayer\Apk\

copied the UnityManifest.xml and renaming it into Assets/Plugins/Android/AndroidManifest.xml

and then adding the line at the tag like this:

<?xml version="1.0" encoding="utf-8"?>
<!-- GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN-->
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
    xmlns:tools="http://schemas.android.com/tools">
    <application android:allowBackup="false"  tools:replace="android:allowBackup">
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:theme="@style/UnityThemeSelector">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
        </activity>
    </application>
</manifest>

That seems to be working.

Thank you.

1 Like

But it replaces the whole manifest

You can add any number of AndroidManifest files and Unity will merge those automatically while building.

But Unity will use our manifest file. It doesn’t merge it with its default manifest file. Does it?

Yes, right.
Unity merges the manifests taken from android plugins. If you want to add any extra info, either update the default manifest or add a new in the form of android plugin project (recommended).

Let me explain why we recommend to add android plugin instead of overriding default one.

  1. It gives more flexibility (as new unity versions may change its default manifest contents)
  2. It’s actually easy to setup than you think.

Steps to create a quick android project

  1. Create a new folder named yourModuleName.androidlib in Assets/Plugins/Android
  2. Create AndroidManifest.xml in the above folder and update with your contents
  3. Create project.properties file with below contents and save it.
target=android-30
android.library=true

Now Unity auto merges the your file and you are free from unity updates which is more flexible!
Added a sample androidlib folder for your reference.

7688665–961864–test.androidlib.zip (2.79 KB)

1 Like