Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions Documentation~/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,18 @@ If you need to recompile AAR library, for example, change `compileSdk` or `minSd

### Manifest

Patch manifest and make sure your `AndroidManifest.xml` has the following setting:

```xml
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustNothing">
...
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
...
</activity>
```

The `adjustNothing` option has been added to prevent the screen from shifting up when the keyboard is displayed.
UMI will patch your manifest at build time with the required settings in a way that plays nicely with other plugins/frameworks. It adds the `adjustNothing` option to your entry activity which will prevent the screen from shifting up when the keyboard is displayed.

> [!NOTE]
> Activity name may vary
> If UMI is unable to patch your manifest automatically, it'll warn you about it when you build your game. In this case, you can make the changes to your manifest yourself. Make sure your `AndroidManifest.xml` has the following setting (Your activity name may vary):
> ```xml
><activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustNothing">
> ...
> <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
> ...
></activity>
>```


## iOS

Expand Down
52 changes: 52 additions & 0 deletions Editor/AndroidManifestPatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#if UNITY_EDITOR && UNITY_ANDROID
using UnityEngine;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using UnityEditor.Android;

namespace UMI {
public class AndroidManifestPatcher : IPostGenerateGradleAndroidProject {
public int callbackOrder => 0;

public void OnPostGenerateGradleAndroidProject(string path) {
XNamespace android = "http://schemas.android.com/apk/res/android";
var manifestPath = Path.Combine(path, "src", "main", "AndroidManifest.xml");

if (!File.Exists(manifestPath)) {
WarnAboutFailure("Unable to locate and patch your Android Manifest");
return;
}

var doc = XDocument.Load(manifestPath);

// Find the first activity that has an intent-filter with MAIN + LAUNCHER
// This works for both classic Activity and GameActivity (2023.1+) application entry
var activity = doc
.Descendants("activity")
.FirstOrDefault(a =>
a.Elements("intent-filter").Any(f =>
f.Elements("action")
.Any(x => (string)x.Attribute(android + "name") == "android.intent.action.MAIN") &&
f.Elements("category")
.Any(x => (string)x.Attribute(android + "name") == "android.intent.category.LAUNCHER")
)
);

if (activity == null) {
WarnAboutFailure("Unable to locate the main launcher activity in your AndroidManifest.xml");
return;
}
activity.SetAttributeValue(android + "windowSoftInputMode", "adjustNothing");
doc.Save(manifestPath);
#if UMI_DEBUG
Debug.Log($"[UMI] Patched AndroidManifest.xml at {manifestPath} with 'adjustNothing' for windowSoftInputMode.");
#endif

void WarnAboutFailure(string reason) {
Debug.LogWarning($"[UMI] {reason}. Please refer to the documentation and ensure you've updated your AndroidManifest.xml manually with the required changes.");
}
}
}
}
#endif
2 changes: 2 additions & 0 deletions Editor/AndroidManifestPatcher.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,7 @@ The iOS plugin is simple, with only 3 files. If you want to know how it works un

Android plugin is a compiled AAR library. All sources are available in [Android~](./Android~/) folder. You can edit the android part and recompile the library to suit your needs.

Make sure your `AndroidManifest.xml` has the following setting:

```xml
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustNothing">
...
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
...
</activity>
```

The `adjustNothing` option has been added to prevent the screen from shifting up when the keyboard is displayed.
Your Android Manifest will be patched automatically at build time with the required settings. Refer to the [docs](Documentation~/index.md#manifest) for details on what is being changed.

### Unity

Expand Down
8 changes: 0 additions & 8 deletions Samples~/Demo/Plugins.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Samples~/Demo/Plugins/Android.meta

This file was deleted.

17 changes: 0 additions & 17 deletions Samples~/Demo/Plugins/Android/AndroidManifest.xml

This file was deleted.

7 changes: 0 additions & 7 deletions Samples~/Demo/Plugins/Android/AndroidManifest.xml.meta

This file was deleted.