Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Android' started by pablo_leban, Mar 17, 2021.

  1. pablo_leban

    pablo_leban

    Joined:
    Sep 19, 2013
    Posts:
    68
    Hi! I just want to add this line to the manifest to not allow Google Play from doing the autobackup of my game.

    Code (CSharp):
    1. <application android:allowBackup="false"  tools:replace="android:allowBackup"></application>
    However according to this link https://docs.unity3d.com/Manual/android-manifest.html, 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.
     
    Last edited: Mar 17, 2021
    kalibcrone likes this.
  2. pablo_leban

    pablo_leban

    Joined:
    Sep 19, 2013
    Posts:
    68
    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 <application> tag like this:

    Code (xml):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <!-- GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN-->
    3. <manifest
    4.     xmlns:android="http://schemas.android.com/apk/res/android"
    5.     package="com.unity3d.player"
    6.     xmlns:tools="http://schemas.android.com/tools">
    7.     <application android:allowBackup="false"  tools:replace="android:allowBackup">
    8.         <activity android:name="com.unity3d.player.UnityPlayerActivity"
    9.                   android:theme="@style/UnityThemeSelector">
    10.             <intent-filter>
    11.                 <action android:name="android.intent.action.MAIN" />
    12.                 <category android:name="android.intent.category.LAUNCHER" />
    13.             </intent-filter>
    14.             <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    15.         </activity>
    16.     </application>
    17. </manifest>
    That seems to be working.

    Thank you.
     
    Voxel-Busters likes this.
  3. ddadkhah

    ddadkhah

    Joined:
    Nov 6, 2017
    Posts:
    59
    But it replaces the whole manifest
     
  4. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,952
    You can add any number of AndroidManifest files and Unity will merge those automatically while building.
     
  5. ddadkhah

    ddadkhah

    Joined:
    Nov 6, 2017
    Posts:
    59
    But Unity will use our manifest file. It doesn't merge it with its default manifest file. Does it?
     
  6. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,952
    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.

    Code (CSharp):
    1. target=android-30
    2. 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.
     

    Attached Files:

    Shronky likes this.