iOS Build Environment Help Center

xcrun missing - failure with ARFoundation/ARKit in Unity

append delete Stephen

Windows 10
Unity 2021.3.9f1
iOS Builder version 3.52
iOS SDK 16.0

Hello - when I try to build an AR project (even the samples), the build will complete, but it fails to work at runtime. It looks like it is missing an Xcode utility to copy some internal files into place. This output appears in the build output:

`DisplayProgressbar: Compiling XRReferenceImageLibrary (1 of 3)
xcrun (an Xcode tool) was not found. This is necessary to bake ARKit-specific data into an XRReferenceImageLibrary. XRReferenceImageLibrary assets will not work in asset bundles.
<snip>`

And then later (though I assume this is just a consequence of the above failures):

`DirectoryNotFoundException: Could not find a part of the path "Build.ipa\Unity-iPhone\ARReferenceImages.xcassets\ReferenceImageLibrary_08BA87F6-226F-4747-ACC4-F6F44538336F.arresourcegroup\QRCode_28D1137F-1DCF-114B-945C-6CF3D6794BC6.arreferenceimage\Contents.json"
<snip>`

Any thoughts? Thanks for your time!

Reply RSS

Replies

append delete #1. Pierre-Marie Baty

Hello

Normally the AR assets (such as AR reference images) are compiled into an Assets.car file, which is the format Apple uses to store AR related data in iOS apps, using the "cartool" asset compiler (an implementation of mine which is specific to this builder) when it detects some. Indeed "xcrun" and "ibtool" don't exist in this toolchain, because Apple published neither their source nor their specifications.

The asset compiler detects data that needs to be compiled when such data is referenced in the Xcode project file. But if your Xcode project relies on a script to bake things "by hand" at build time, like what seems to be the case here, these assets won't appear as resources in the Xcode project and probably won't be detected by the builder.

Could you share that Xcode project with me so that I have a closer look at what needs to be fixed please ? You may send it at pm @ this domain.

Thanks

append delete #2. Stephen

Hello,

I sent you both the Unity project and the exported Xcode project. Just to be clear - the output about xrcun missing comes from Unity when it is exporting the AR project, it is not a custom script that I have added to the project. I'm guessing that is some recent change to Unity's AR export process.

Thanks!

append delete #3. Pierre-Marie Baty

I've downloaded your project today and had a look at it.

Indeed the builder won't be able to build a working app out of it, because it is incomplete: the UnityData.xcassets directory is empty.

I suppose the Unity Builder relies on xcrun to copy the AR catalog into this directory, and in absence of this tool on macOS, you get a broken Xcode project.

The only thing you can do here, and what I advise you to do, is to raise the concern about this issue on the Unity forums or near the Unity support team. They should be able to do that (i.e. layout the AR catalog in the Xcode project) without xcrun. The lazy ones will tell you "creating Xcode projects on Windows is not supported in Unity", but insist. I don't see any technical impossibility here. They already *do* create working Xcode projects with the Windows version of the Unity Editor. What they simply need to do is to continue to rely on portable/ubiquitous tools to do so.

:: @Pierre-Marie Baty added on 15 Oct ’22 · 12:59

*edit* typo: "in absence of this tool on macOS" should be read as "...in the absence of this tool on Windows". Phew, I'm tired today.

append delete #4. Stephen

Hello,

That all makes perfect sense, and I will reach out to Unity as you advise. I'll report back here if I get any response from Unity or the forums.

In the meantime, I'm going to try a workaround of dynamically adding the image I need to track to the library manager at runtime.

As always, thank you for your time and wonderful support. It is very much appreciated.

cheers,
Stephen

append delete #5. Pierre-Marie Baty

You're welcome. If you manage to find out a workaround that could be useful for others to know, please post here and I might add it to the documentation.

append delete #6. Stephen

Hi,

I will make a bug report and Unity forum post soon.

In the meantime, happily - the workaround did work. It's just adapting some example code, but posting here in case it saves someone else some time. This does take some runtime processing to do, but for the small QRCode I'm using, it wasn't noticeable. The method first checks to see if the workaround is needed, so it can be run on both builds created on macOS and Windows. I call it from Start in my AR handler.

%
    protected void InitLibraryManager()
    {
        if (!libraryInitialized)
        {
            libraryInitialized = true;

            if (imageManager.referenceLibrary == null)
            {
                imageManager.referenceLibrary = imageManager.CreateRuntimeLibrary();
                if (imageManager.referenceLibrary == null)
                {
                    Debug.LogError("AR: Unable to dynamically create ReferenceLibrary.")
                    return;
                }
            }

            //The number of images can be 0 if we just created the Library above, or if
            //this binary was built on Windows thus failing to copy the images correctly
            //into the build for a referenceLibrary set in the editor.  In either
            //case, we'll dynamically add the image here...
            if (imageManager.referenceLibrary.count == 0)
            {
                Debug.Log("AR: Detected no library images, adding our image dynamically as a workaround...");
                if (imageManager.referenceLibrary is MutableRuntimeReferenceImageLibrary mutableLibrary)
                {
                    Debug.Log("AR: Dynamically adding image.");
                    //imageToTrack must be read/write, RGB24.
                    mutableLibrary.ScheduleAddImageWithValidationJob(imageToTrack, "QRCode", 0.104775f);
                }
                else
                {
                    Debug.LogError("AR: Workaround failed - ImageManager ReferenceLibrary cannot be dynamically added to.");
                }
            }
        }
    }
%
append delete #7. Pierre-Marie Baty

Excellent. I'll update the FAQ in the documentation with a link to this thread. Thank you very much for sharing.

append delete #8. Kris Rok
append delete #9. Pierre-Marie Baty

That's indeed the same problem. andyb-unity's answer was meaningful and likely to solve the issue if everything was working as designed, but it looks like the Unity editor doesn't like the absence of xcrun, even when you tell it that the reference images should not be embedded in an asset bundle (and thus even when it doesn't need xcrun at all).

Stephen's answer here is a good way of addressing the problem, by creating the library and adding these images at runtime.

append delete #10. Marc Peiro

Hello,

I am having the same problem. How can I apply this solution in my project?
Thanks in advance.
Marc

append delete #11. Pierre-Marie Baty

Hello Marc

Because the problem happens while the Unity editor is generating the Xcode project, I suggest you ask this in the Unity forum, where you can reach out to these people directly. Unfortunately the builder doesn't control the way the Unity editor behaves.

One "workaround" (rather a "hack") that could be investigated, would be to provide a fake "xcrun.exe" executable in the user's PATH, that Unity would be lured into calling. You could make this fake xcrun start by displaying its full command line arguments, which would instruct you about what the Unity editor intends to call it for. And once you know that, reimplement that step, either in xcrun.exe yourself, or in a custom build phase of your own.

:: @Pierre-Marie Baty added on 09 Dec ’23 · 12:36

*edit* the command-line usage of xcrun looks rather simple: https://www.manpagez.com/man/1/xcrun/
I guess what's interesting to know is which tool the Unity editor wants to call through xcrun, and with which arguments.

append delete #12. Marc Peiro

Hello, thank you.
I tried to use Stephen's solution in the meantime. However, I get the following bug: AR: Workaround failed - ImageManager ReferenceLibrary cannot be dynamically added to.

How is it possible that my referenceLibrary is not mutable, but Stephen's one is?
I am trying AR foundation version 4.2.9. Does it has something to do with it?
Kind regards, Marc

append delete #13. Pierre-Marie Baty

Unfortunately that is beyond my expertise. Maybe someone at the Unity forums could help.

Reply

(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Moderators: Pierre-Marie Baty