Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AR Foundation instructions and fix missing XRmanifest.androidlib #911

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,29 +378,52 @@ allprojects {
The following setup for AR is done after making an export from Unity.


<b>Warning: The `XR Plugin Management` package version `4.3.1 - 4.3.3` has bug that breaks Android exports. </b>
<b>Warning: The `XR Plugin Management` package version `4.3.1 - 4.3.3` has a bug that breaks Android exports. </b>

- The bug accidentally deletes your AndroidManifest.xml file after each build, resulting in a broken export.
Switch to version `4.2.2` or `4.4` to avoid this.
You might have to manually change the version in `<unity project>/Packages/manifest.json` to `"com.unity.xr.management": "4.4.0",`

<details>
<summary>:information_source: <b>AR Foundation Android</b></summary>

1. You can check the `android/unityLibrary/libs` folder to see if AR was properly exported. It should contain files similar to `UnityARCore.aar`, `ARPresto.aar`, `arcore_client.aar` and `unityandroidpermissions.aar`.

If your setup and export was done correctly, your project should automatically load these files.
If it doesn't, check if your `android/build.gradle` file contains the `flatDir` section added in the android setup step 7.

2. If your `XR Plugin Management` plugin is version 4.4 or higher, Unity also exports the xrmanifest.androidlib folder.
Make sure to include it by adding the following line to `android/settings.gradle`
```
include ":unityLibrary:xrmanifest.androidlib"
```
3. With some Unity versions AR might crash at runtine with an error like:
`java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "mUnityPlayer" in class`.
See the Android setup step 3 on how to edit your MainActivity to fix this.

4. When using UnityWidget in Flutter, set fullscreen: false to disable fullscreen.

<details><summary>Legacy AR Foundation instructions</summary></summary>

7. Open the *lib/__architecture__/* folder and check if there are both *libUnityARCore.so* and *libarpresto_api.so* files.
There seems to be a bug where a Unity export does not include all lib files. If they are missing, use Unity to build a standalone .apk
of your AR project, unzip the resulting apk, and copy over the missing .lib files to the `unityLibrary` module.

8. Repeat steps 5 and 6 from the Android <b>Platform specific setup</b> (editing build.gradle and settings.gradle), replacing `unityLibrary` with `arcore_client`, `unityandroidpermissions` and `UnityARCore`.

9. When using `UnityWidget` in Flutter, set `fullscreen: false` to disable fullscreen.


</details>


-----
</details>

<details>
<summary>:information_source: <b>AR Foundation iOS</b></summary>
7. Open the *ios/Runner/Info.plist* and change the following:

1. Open the *ios/Runner/Info.plist* and add a camera usage description.
For example:
```diff
<dict>
+ <key>NSCameraUsageDescription</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ private static void SetupAndroidProject()
}


// The XR management package might export an xrmanifest folder, also include this in settings.gradle
string xrmanifest = Path.Combine(APKPath, "unityLibrary", "xrmanifest.androidlib");
if (Directory.Exists(xrmanifest) && !settingsScript.Contains("xrmanifest.androidlib")) {
settingsScript += "\ninclude \":unityLibrary:xrmanifest.androidlib\"";
File.WriteAllText(settingsPath, settingsScript);
}


// Sets up the project app build.gradle files correctly
if (!Regex.IsMatch(appBuildScript, @"dependencies \{"))
{
Expand Down