Skip to main content
New Participant
July 3, 2026
Question

Unity Meta XR Core SDK Build and Run Failed

  • July 3, 2026
  • 1 reply
  • 93 views

Hi everyone,

I'm a Unity VR developer at VinRobotics. I ran into a build failure with the Meta XR Core SDK during my daily work, spent some time digging into the SDK source, and found the root cause - sharing it here so others hit by the same error can find it, and hopefully so the SDK team can fix it upstream.

UpdateManifestWithCodeSample scans stale gradle intermediates whose paths can exceed Windows MAX_PATH (260 chars), so the first build succeeds but every following Build / Build And Run fails. Root cause analysis, repro steps, and a quick permanent fix below.

Environment
  • Unity 6000.3.11f1
  • Meta XR Core SDK 201.0.0 (issue exists in earlier versions too)
  • Windows 11, LongPathsEnabled registry = 0 (OS default)
  • IL2CPP, Android build target (Quest 3)
Symptom

The only Build .apk succeeds. But every Build And Run fails during post-processing with:

DirectoryNotFoundException: Could not find a part of the path
"<ProjectRoot>\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\xrmanifest.androidlib\build\intermediates\aapt_friendly_merged_manifests\release\processReleaseManifest\aapt\AndroidManifest.xml"
  at System.IO.FileStream..ctor (...)
  at System.Xml.XmlDocument.Load (...)
  at Meta.XR.Samples.Editor.UpdateManifestWithCodeSample.UpdateManifest (...)
  at Meta.XR.Samples.Editor.UpdateManifestWithCodeSample.OnPostGenerateGradleAndroidProject (...)
Root cause

The failing script is inside the Meta XR Core SDK package:

Packages/com.meta.xr.sdk.core/Editor/Utils/SampleMetadata/UpdateManifestWithCodeSample.cs

In OnPostGenerateGradleAndroidProject (line ~47) it does:

var manifestFiles = Directory.GetFiles(Path.Combine(path, ".."),
    "AndroidManifest.xml", SearchOption.AllDirectories);

This enumerates every AndroidManifest.xml under the gradle root - including stale merged manifests inside build/intermediates/ left over from the previous gradle build. That is why the first build passes (no intermediates yet) and all later builds fail. Each stale file is then passed to UpdateManifest(), which calls XmlDocument.Load on it (line ~74).

The stale path under xrmanifest.androidlib adds ~179 characters on top of the project root. With a project root of ~80+ characters the full path reaches 260 characters - exactly the Windows MAX_PATH limit - and Mono's FileStream throws DirectoryNotFoundException inside XmlDocument.Load.

Steps to reproduce
  1. Windows machine with default LongPathsEnabled = 0, project located at a path of ~80+ characters (nested folders are enough).
  2. Unity project with Meta XR Core SDK, Android target, Quest configured (so xrmanifest.androidlib is generated).
  3. Click Build And Run - post-process fails with the exception above.
Suggested fix (SDK side)

Patching manifests inside build/intermediates/ is pointless anyway - gradle regenerates them during the build. Please filter the enumeration to source manifests only, e.g. skip any path containing \build\intermediates\, and/or wrap XmlDocument.Load in a try/catch so one unreadable file doesn't abort the whole build.

Note: the same broad enumeration also breaks builds in other setups, e.g. with Firebase: https://github.com/firebase/firebase-unity-sdk/issues/1360

🔑 Workaround (quick fix)
  1. Save the script below as CleanStaleAndroidLibIntermediates.cs in any "Editor" folder in your project, e.g. Assets/Editor/
  2. Build again. Done - the error is gone and will not come back.

The script runs automatically on every Android build, right before the Meta SDK callback, and deletes the stale androidlib build folders.

using System.IO;
using UnityEditor.Android;

// Deletes stale *.androidlib build/intermediates before Meta SDK's
// UpdateManifestWithCodeSample scans them (fixes MAX_PATH build failure).
public class CleanStaleAndroidLibIntermediates : IPostGenerateGradleAndroidProject
{
    public int callbackOrder => -1; // must run before Meta's callback (order 0)

    public void OnPostGenerateGradleAndroidProject(string path)
    {
        var gradleRoot = Path.GetFullPath(Path.Combine(path, ".."));
        foreach (var lib in Directory.GetDirectories(gradleRoot, "*.androidlib", SearchOption.AllDirectories))
        {
            var build = Path.Combine(lib, "build");
            if (!Directory.Exists(build))
                continue;

            // Files inside can exceed MAX_PATH, which plain Directory.Delete
            // can't handle on Mono - use rd with the \\?\ long-path prefix.
            var psi = new System.Diagnostics.ProcessStartInfo
            {
                FileName = "cmd.exe",
                Arguments = "/c rd /s /q \"\\\\?\\" + build + "\"",
                CreateNoWindow = true,
                UseShellExecute = false,
            };
            System.Diagnostics.Process.Start(psi)?.WaitForExit();
        }
    }
}

No script needed? You can also delete the folder below manually, but the error will return after every successful build:

<ProjectRoot>\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\xrmanifest.androidlib\build

Alternative mitigations: enable Windows long paths (HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled = 1) or move the project to a shorter path - but the SDK-side filter is the real fix.

1 reply

steve40
Honored Contributor
July 4, 2026

If you want the SDK team to take note, you should submit this to the official Developer Feedback Center.