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

Problem modifying AndroidManifest.xml

Discussion in 'Android' started by reder-it, Aug 17, 2019.

  1. reder-it

    reder-it

    Joined:
    Jun 13, 2019
    Posts:
    1
    I am trying to change android:smallScreens to false to exclude devices with small screens but I am getting a build error.

    Error2.PNG

    Error1.PNG

    I am using the following AndroidManifest.xml in /Assets/Plugins/Android/AndroidManifest.xml to override the value:

    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest
    3.     xmlns:android="http://schemas.android.com/apk/res/android"
    4.     package="com.unity3d.player"
    5.     xmlns:tools="http://schemas.android.com/tools"
    6.     android:installLocation="preferExternal">
    7.     <supports-screens
    8.         android:smallScreens="false"
    9.         android:normalScreens="true"
    10.         android:largeScreens="true"
    11.         android:xlargeScreens="true"
    12.         android:anyDensity="true"
    13.         tools:replace="android:smallScreens"/>
    14.  
    15.     <application
    16.         android:theme="@style/UnityThemeSelector"
    17.         android:icon="@mipmap/app_icon"
    18.         android:label="@string/app_name">
    19.         <activity android:name="com.unity3d.player.UnityPlayerActivity"
    20.                   android:label="@string/app_name">
    21.             <intent-filter>
    22.                 <action android:name="android.intent.action.MAIN" />
    23.                 <category android:name="android.intent.category.LAUNCHER" />
    24.             </intent-filter>
    25.             <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    26.         </activity>
    27.     </application>
    28. </manifest>
    29.  
    I already added tools:replace="android:smallScreens" trying to fix the problem but it doesnt help

    Unity version is 2019.3.0a11
     
  2. shinji89

    shinji89

    Joined:
    Sep 24, 2019
    Posts:
    2
    Yesterday I update Unity to 2019.3.* and I have the same issue.
    Before update (version 2019.2.*) the same code (even without tools:replace) worked perfectly.
    Something must change beetwen ths version.
    For now - this is ugly hack, not fix - you can change Unity source manifest file located in:
    [UnityInstalation]\Editor\Data\PlaybackEngines\AndroidPlayer\
     
  3. Jahidulh

    Jahidulh

    Joined:
    Jul 26, 2018
    Posts:
    3
    I have the same issue too
     
  4. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    835
    The supported screens element was moved to the launcher manifest. There is no official way to modify this manifest in Unity editor. You will have to export your project, then modify the launcher manifest the way you want and finally build the project using Android Studio.
     
  5. Marc-Uberstein

    Marc-Uberstein

    Joined:
    Apr 10, 2013
    Posts:
    9
    @JuliusM Can you guys please remove the supported screens section out of the launcher manifest, or give the user the option via the Unity Editor to enable/disable this.
     
  6. fbta

    fbta

    Joined:
    Apr 23, 2017
    Posts:
    1
    How can we get around this issue when using Unity Cloud Build? Modifying the source manifest is not an option there.

    Any idea when this will be resolved?
     
  7. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    835
    We are working on allowing to overwrite manifest and gradle templates for both launcher and unity projects.
     
  8. infosekr

    infosekr

    Joined:
    Jul 12, 2013
    Posts:
    46
    Does anyone have a workaround until @JuliusM has a fix in a new version of Unity?
     
  9. Deepakvrm354

    Deepakvrm354

    Joined:
    Apr 7, 2020
    Posts:
    1
    I have the same issue too
     
  10. levius

    levius

    Joined:
    Jun 18, 2016
    Posts:
    19
    + (unity3d version 2019.3.10f1)
     
    Last edited: Apr 19, 2020
  11. infosekr

    infosekr

    Joined:
    Jul 12, 2013
    Posts:
    46
    I found an example using the OnPostGenerateGradleAndroidProject() callback to edit the manifest during the build. But this is called before the gradleOut\launcher\src\main\ manifest is merged with the gradleOut\unityLibrary\src\main\ manifest, so the conflict will still happen even if I edit the unityLibrary version.

    @JuliusM can you suggest a workaround to this problem? Can we edit the merged manifest in code somehow?
     
    Last edited: Apr 20, 2020
  12. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    835
    The option to overwrite templates have been added to Unity 2020.1.0b2 and 2019.3.7f1. Also an option to overwrite gradle properties template was added to Unity 2018.4.21f1.
    upload_2020-4-20_13-32-0.png
     
    junneru10, grrava and WhiteGfx like this.
  13. infosekr

    infosekr

    Joined:
    Jul 12, 2013
    Posts:
    46
  14. levius

    levius

    Joined:
    Jun 18, 2016
    Posts:
    19
    @JuliusM
    "The option to overwrite templates have been added to Unity 2020.1.0b2 and 2019.3.7f1. Also an option to overwrite gradle properties template was added to Unity 2018.4.21f1."

    It's doesn't work for me.

    Custom Main Manifest (Assets/Plugins/Android/AndroidManifest.xml):
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" package="ru.yandex.mobile.metricapluginunity" android:versionCode="1" android:versionName="1.0">
    3.   <uses-sdk android:minSdkVersion="17" />
    4.   <uses-permission android:name="android.permission.INTERNET" />
    5.   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    6.   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    7.   <supports-screens android:resizeable="true" android:smallScreens="false" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
    8.   <application android:label="@string/app_name" android:icon="@drawable/app_icon">
    9.     <service android:name="com.yandex.metrica.MetricaService" android:enabled="true" android:exported="true" android:process=":Metrica">
    10.       <intent-filter>
    11.         <category android:name="android.intent.category.DEFAULT" />
    12.         <action android:name="com.yandex.metrica.IMetricaService" />
    13.         <data android:scheme="metrica" />
    14.       </intent-filter>
    15.       <meta-data android:name="metrica:api:level" android:value="45" />
    16.     </service>
    17.     <receiver android:name="com.yandex.metrica.MetricaEventHandler" android:enabled="true" android:exported="true">
    18.       <intent-filter>
    19.         <action android:name="com.android.vending.INSTALL_REFERRER" />
    20.       </intent-filter>
    21.     </receiver>
    22.     <activity android:name="com.unity3d.player.UnityPlayerActivity" android:configChanges="keyboardHidden|orientation" android:label="@string/app_name">
    23.       <intent-filter>
    24.         <action android:name="android.intent.action.MAIN" />
    25.         <category android:name="android.intent.category.LAUNCHER" />
    26.       </intent-filter>
    27.     </activity>
    28.     <activity android:name="com.facebook.unity.FBUnityLoginActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    29.     <activity android:name="com.facebook.unity.FBUnityDialogsActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    30.     <activity android:name="com.facebook.unity.FBUnityAppLinkActivity" android:exported="true" />
    31.     <activity android:name="com.facebook.unity.FBUnityDeepLinkingActivity" android:exported="true" />
    32.     <activity android:name="com.facebook.unity.FBUnityGameRequestActivity" />
    33.     <activity android:name="com.facebook.unity.FBUnityCreateGameGroupActivity" />
    34.     <activity android:name="com.facebook.unity.FBUnityJoinGameGroupActivity" />
    35.     <activity android:name="com.facebook.unity.AppInviteDialogActivity" />
    36.     <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="fb1782681958640904" />
    37.     <provider android:name="com.facebook.FacebookContentProvider" android:authorities="com.facebook.app.FacebookContentProvider1782681958640904" android:exported="true" />
    38.   </application>
    39. </manifest>
    Unity generated this (Temp/gradleOut/launcher/src/main/AndroidManifest.xml):
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <!-- GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN-->
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.levius.afterlifeidle" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal">
    4.   <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
    5.   <application android:label="@string/app_name" android:icon="@mipmap/app_icon" />
    6. </manifest>
    And result:
    AndroidManifest.xml:4:21-48 Error:
    Attribute supports-screens@smallScreens value=(true) from AndroidManifest.xml:4:21-48
    is also present at [:unityLibrary] AndroidManifest.xml:21:9-37 value=(false).
    Suggestion: add 'tools:replace="android:smallScreens"' to <supports-screens> element at AndroidManifest.xml:4:3-163 to override.

    In old version all compiling fine. In 2019.3 I can't build android version. Maybe I don't understand how it works?
     
    Last edited: Apr 23, 2020
  15. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    835
    Assets/Plugins/Android/AndroidManifest.xml overwrites the main manifest, so the launcher manifest does not get overwritten. Since supports-screens is already added to a default launcher manifest, you get this error. You will have to overwrite launcher manifest as well.
     
  16. unity_QWc9-aAgcjqjzg

    unity_QWc9-aAgcjqjzg

    Joined:
    Mar 23, 2020
    Posts:
    4
    I managed to work around this limitation by changing the AndroidManifest.xml from the Unity installation (I'm using 2018.4.19f1). In my case the file is located at: D:\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Apk .. it's a dirty hack but could be useful to skip this limitation ..
     
    Last edited: Apr 29, 2020
    kidsadmin likes this.
  17. ash4096

    ash4096

    Joined:
    Mar 29, 2017
    Posts:
    24
    Having the same issue ...

    Where should I put my custom manifest file to override Unity's LauncherManifest.xml
    I am using Cloud Build so I can't modify the APK.

    Thanks,
    Ash
     
  18. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    835
    Since Unity 2019.3.7f1 there is an option in the player settings -> publishing settings allowing to provide a custom launcher manifest. Enable the checkbox and a launcher manifest will be created in your project's Plugins/Android directory, then you can modify the template. See my post above #12
     

    Attached Files:

    Sailendu, jctn, Ex6tra and 1 other person like this.
  19. ash4096

    ash4096

    Joined:
    Mar 29, 2017
    Posts:
    24
    Thanks Julius
     
  20. unity_QWc9-aAgcjqjzg

    unity_QWc9-aAgcjqjzg

    Joined:
    Mar 23, 2020
    Posts:
    4
    I managed to fix this issue by creating my own Manifest.xml in the relative path Assets\Plugins\Android\Manifest.xml putting my manifest there Unity use it instead of the default one (in my installation C:\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\)
     
  21. jctn

    jctn

    Joined:
    Mar 27, 2017
    Posts:
    1
     
  22. Sailendu

    Sailendu

    Joined:
    Jul 23, 2009
    Posts:
    254
    Thanks a lot for posting this, I was looking for many hours about how to edit the manifest file, then your post about this "Custom Main Manifest" checkbox finally did the trick. Thank you so much again.
     
  23. unity_b2AbrmGM17zHJA

    unity_b2AbrmGM17zHJA

    Joined:
    Feb 22, 2021
    Posts:
    2
    What should be the exact instruction to put in the LauncherGradleTemple according to override supports-screens?