Problem modifying AndroidManifest.xml

I am trying to change android:smallScreens to false to exclude devices with small screens but I am getting a build error.

4867448--468995--Error2.PNG

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

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
    xmlns:tools="http://schemas.android.com/tools"
    android:installLocation="preferExternal">
    <supports-screens
        android:smallScreens="false"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"
        android:anyDensity="true"
        tools:replace="android:smallScreens"/>

    <application
        android:theme="@style/UnityThemeSelector"
        android:icon="@mipmap/app_icon"
        android:label="@string/app_name">
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:label="@string/app_name">
            <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>

I already added tools:replace=“android:smallScreens” trying to fix the problem but it doesnt help

Unity version is 2019.3.0a11

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\

2 Likes

I have the same issue too

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.

@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.

4 Likes

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?

We are working on allowing to overwrite manifest and gradle templates for both launcher and unity projects.

3 Likes

Does anyone have a workaround until @JuliusM has a fix in a new version of Unity?

I have the same issue too

  • (unity3d version 2019.3.10f1)

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?

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.

3 Likes

@JuliusM thank you!

@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):

<?xml version="1.0" encoding="utf-8"?>
<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">
  <uses-sdk android:minSdkVersion="17" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <supports-screens android:resizeable="true" android:smallScreens="false" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:label="@string/app_name" android:icon="@drawable/app_icon">
    <service android:name="com.yandex.metrica.MetricaService" android:enabled="true" android:exported="true" android:process=":Metrica">
      <intent-filter>
        <category android:name="android.intent.category.DEFAULT" />
        <action android:name="com.yandex.metrica.IMetricaService" />
        <data android:scheme="metrica" />
      </intent-filter>
      <meta-data android:name="metrica:api:level" android:value="45" />
    </service>
    <receiver android:name="com.yandex.metrica.MetricaEventHandler" android:enabled="true" android:exported="true">
      <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
      </intent-filter>
    </receiver>
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:configChanges="keyboardHidden|orientation" android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <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" />
    <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" />
    <activity android:name="com.facebook.unity.FBUnityAppLinkActivity" android:exported="true" />
    <activity android:name="com.facebook.unity.FBUnityDeepLinkingActivity" android:exported="true" />
    <activity android:name="com.facebook.unity.FBUnityGameRequestActivity" />
    <activity android:name="com.facebook.unity.FBUnityCreateGameGroupActivity" />
    <activity android:name="com.facebook.unity.FBUnityJoinGameGroupActivity" />
    <activity android:name="com.facebook.unity.AppInviteDialogActivity" />
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="fb1782681958640904" />
    <provider android:name="com.facebook.FacebookContentProvider" android:authorities="com.facebook.app.FacebookContentProvider1782681958640904" android:exported="true" />
  </application>
</manifest>

Unity generated this (Temp/gradleOut/launcher/src/main/AndroidManifest.xml):

<?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.levius.afterlifeidle" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:label="@string/app_name" android:icon="@mipmap/app_icon" />
</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 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?

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.

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 …

1 Like

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

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

5927204--633710--upload_2020-6-1_21-56-44.png

4 Likes

Thanks Julius

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)*