Android: Unable to load pages from StreamingAssets when "Split Application Binary" is enabled

3D WebView for Android is powered by the Android System WebView, and unfortunately the System WebView doesn't support loading web pages from StreamingAssets when the "Split Application Binary" option is enabled in "Android Player Settings" -> "Publishing Settings". If you encounter this issue, here are options to resolve it:

  1. The first option is to disable "Split Application Binary".

  2. Or you can copy the assets to a different location (such as Application.temporaryCachePath) and then load them via a file:// URL like described here. Here's an example:

using System;
using System.IO;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Networking;
using Vuplex.WebView;

class LoadFileFromCachePath : MonoBehaviour {

    // TODO: Set these fields via the Editor's inspector tab.
    public string fileName;
    public BaseWebViewPrefab webViewPrefab;

    async void Start() {

        Assert.IsTrue(!String.IsNullOrEmpty(fileName), "The fileName field on the LoadFileFromCachePath script hasn't been set. Please set it via the Editor inspector tab.");
        Assert.IsNotNull(webViewPrefab, "The webViewPrefab field on the LoadFileFromCachePath script hasn't been set. Please set it via the Editor inspector tab.");

        var fileText = await _getStreamingAssetsFileText();
        var temporaryCacheFilePath = Path.Combine(Application.temporaryCachePath, fileName);
        File.WriteAllText(temporaryCacheFilePath, fileText);

        // Wait for the prefab to initialize.
        // https://developer.vuplex.com/webview/WebViewPrefab#WaitUntilInitialized
        await webViewPrefab.WaitUntilInitialized();

        // Load the file from Application.temporaryCachePath using a file URL.
        var fileUrl = "file://" + temporaryCacheFilePath;
        webViewPrefab.WebView.LoadUrl(fileUrl);
    }

    Task<string> _getStreamingAssetsFileText() {

        var streamingAssetsFilePath = Path.Combine(Application.streamingAssetsPath, fileName);
        var taskSource = new TaskCompletionSource<string>();
        #if UNITY_ANDROID && !UNITY_EDITOR
            // On Android, StreamingAssets are compressed inside the APK, so they can't be accessed via
            // C# file APIs and must instead be accessed via UnityWebRequest:
            // https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html
            using (UnityWebRequest webRequest = UnityWebRequest.Get(streamingAssetsFilePath)) {
                webRequest.SendWebRequest().completed += (_) => {
                    if (webRequest.result == UnityWebRequest.Result.Success) {
                        taskSource.SetResult(webRequest.downloadHandler.text);
                    } else {
                        taskSource.SetException(new Exception("UnityWebRequest was unsuccessful: " + webRequest.result));
                    }
                };
            }
        #else
            // On other platforms (like the Editor), StreamingAssets can be accessed via file APIs.
            var text = File.ReadAllText(streamingAssetsFilePath);
            taskSource.SetResult(text);
        #endif
        return taskSource.Task;
    }
}