How to make Vuforia with aab and split binary work?

I’m experiencing a persistent issue where the Vuforia database is not recognized when I build my app as an Android App Bundle (AAB) with split binary options. However, when I build the project as an APK, everything functions correctly.

Here’s what I’ve explored so far:

I understand that there are specific considerations with the StreamingAssets folder in AAB, such as potential delays in downloading contents. I attempted to package the Vuforia database using AssetBundles. Unfortunately, it seems that the .dat file cannot be included in an AssetBundle. For reference, the app does upload and I can open it. It is just Vuforia which doesnt work!

I have a loading scene in Unity and my main Scene which gets loaded after

Setup Details:

Unity 2022.3.25f1
Vuforia 10.22.5
Build App Bundle (Google Play) [Check]
Split Application Binary [Check]

Base Scene Size: ~50MB
Main Scene Size: ~1.5GB

I’ve spent numerous hours over several nights trying to resolve this without success. Does anyone have suggestions on how to ensure the Vuforia database is properly recognized and loaded in an AAB format? Any insights or fixes would be greatly appreciated.

Thank you, MotionBrain

I tried this to delay the streaming asset folder.

  IEnumerator Start()
    {

#if UNITY_EDITOR
        yield return null;
#else
            string[] assetPackNames = AndroidAssetPacks.GetCoreUnityAssetPackNames();
            if (!AndroidAssetPacks.coreUnityAssetPacksDownloaded)
            {
                yield return StartCoroutine(WaitForAssetPacksDownload(assetPackNames));
            }
            else{
                yield return StartCoroutine(CheckAssetPacksDownloaded(assetPackNames));
            }
#endif

    }

    IEnumerator WaitForAssetPacksDownload(string[] assetPackNames)
    {
        bool allDownloaded = false;
        // App cannot load without UnityStreamingAssetsPack being downloaded first
        while (!allDownloaded)
        {
            var operation = AndroidAssetPacks.GetAssetPackStateAsync(assetPackNames);
            yield return operation; // Wait for the state check to complete
            if (operation.isDone)
            {
                allDownloaded = true;
            }
            if (!allDownloaded)
            {
                // Wait before checking again to avoid spamming checks
                yield return new WaitForSeconds(3);
            }
        }
        errorTtext.SetText("All asset packs downloaded.");

        AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(1);
        asyncOperation.allowSceneActivation = false;

        while (!asyncOperation.isDone)
        {
            float progress = asyncOperation.progress * 100;
            loadingPercent.text = (int)progress + "%";

            if (asyncOperation.progress >= 0.90f)
            {
                yield return new WaitForSeconds(5);
                asyncOperation.allowSceneActivation = true;
            }

            yield return null;
        }
      
    }

Thank you,

MotionBrain

Push

Found a Solution:

Reverted to Vuforia 9.8.5.
And used this code while loading my MainScene (the big scene)

    private string datUrl = "url.dat";
    private string xmlUrl = "url.xml";
    private string datasetName = "datasetName";   
    IEnumerator DownloadAndLoadDatasets()
        {
            // Download DAT file
            UnityWebRequest datRequest = UnityWebRequest.Get(datUrl);
            yield return datRequest.SendWebRequest();
            if (datRequest.isNetworkError || datRequest.isHttpError)
            {
                statusText.text += "Failed to download DAT file: " + datRequest.error;
                yield break;
            }
   
            // Download XML file
            UnityWebRequest xmlRequest = UnityWebRequest.Get(xmlUrl);
            yield return xmlRequest.SendWebRequest();
            if (xmlRequest.isNetworkError || xmlRequest.isHttpError)
            {
                statusText.text += "Failed to download XML file: " + xmlRequest.error;
                yield break;
            }
   
            // Save downloaded files
            string datPath = Path.Combine(Application.persistentDataPath, datasetName + ".dat");
            string xmlPath = Path.Combine(Application.persistentDataPath, datasetName + ".xml");
            File.WriteAllBytes(datPath, datRequest.downloadHandler.data);
            File.WriteAllBytes(xmlPath, xmlRequest.downloadHandler.data);
   
            // Load and activate dataset
            LoadAndActivateDataset(datPath, xmlPath);
        }
   
        void LoadAndActivateDataset(string datPath, string xmlPath)
        {
            ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
            DataSet dataSet = objectTracker?.CreateDataSet();
          
            if (dataSet != null /*&& dataSet.Load(xmlPath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)*/)
            {
                objectTracker.Stop();
                objectTracker.ActivateDataSet(dataSet);
                objectTracker.Start();
            }
            else
            {
                statusText.text += "Failed to load dataset.";
            }
        }
1 Like

Congrats on finding a solution, I am nearing the “closed testing” stage of my build, my app is not as big as yours, about 550Mb in total, the base scene is around 40MB and the rest makes up two scenes with Vuforia Image Targets. Are we required to add this code if we check “split application binary” and build an AAB? I’d hate to send my app to the testers, and it doesn’t work right away :confused: