UnityWebRequest.GetAssetBundle from StreamingAssets?

We’ve been using WWW.LoadFromCacheOrDownload to copy asset bundles from StreamingAssets to the cache (for faster loading), but after attempting to switch to using UnityWebRequest.GetAssetBundle, we’re now getting the following error:

A URL Connection to a Java ARchive (JAR) file or an entry in a JAR file is not supported

(the URL is jar:file:///data/app/). Is this use case something that will be supported in future releases, or perhaps is there a more appropriate way to go about getting bundles from StreamingAssets cached with UnityWebRequest? We’re currently on 5.4.0p3. We would use AssetBundle.LoadFromFileAsync to load the file directly, but it takes significantly longer than loading a cached asset bundle, so being able to maintain this usage after WWW is deprecated would be very good for us.

Bump… Did you ever find a solution to this?
It works in the editor but on iOS I get “Received no data in response”.

Bump… still broken in 5.5

The support for this will come out soon in 2017.1.
I’ll probably backport this to older releases too.

I understand that this support it’s not only for Asset Bundles isn’t it? We need it for any file loaded with UnityWebRequest. There are other cases like xml, json, textures, videos…

Yes, even though it is not recommended.
For loading asset bundles from streaming assets you should use AssetBundle.LoadFromFileAsync().
While on Android it’s recommended to not use streaming assets for performance reasons. You are in fact reading from apk, which is a zip file.

Hi! I’m currently working on AssetBundles and I also encounter this kind of problem.

When you say :

What do we should use instead ?
For example, I have some textures variants that I want to load depending on screen resolution of the running device and I have no online server to host my AssetBundles what are my options ?

AssetBundle.LoadFromFileAsync() can load abs from streaming assets and it is the recommended way to do this.

Yes but building an asset bundle implies more steps on workflow than simply putting files in streaming assets folder. Everytime you change something you need to build it for each platform you target. You also need to exclude in resources folder the asset bundles of the platforms that are not the currently one. Also the code to load the assets inside of it is not the same. It’s not a trivial change.

If you want people to start using asset bundles instead of streaming assets you should optimize and automatize this process.

Thank you Aurimas-Cernius for the answer. If I understand correctly, in my case, I cannot avoid to use streaming assets, and I will have to deal with performance when I use AssetBundle.LoadFromFileAsync() on Android devices.

To be sure to understand how AssetBundles works, am I right when I say :

Another way to do handle this, is to have a web server where AssetBundles are stored and have the game calling UnityWeRequest functions to connect and download the bundles. I wonder if it means that the player should always be online when he/she play the game ?

When I read these pages :

I suppose that AssetBundles will be downloaded the very first time the player launch the game and they will be cached. So the next time the player don’t need to be online to play because asset bundles are presents in cache, right ?

That’s how AssetBundles are designed to be used: you download a bundle, cache it and use to from that on until you update your game and a newer version of asset bundle has to be used (or your game somehow finds out that the newer version of asset bundle is available online).
You can ship asset bundle with your game too, but they were designed with download from internet in mind.
Note: make sure you use our APIs properly for asset bundle to be cached, otherwise you will have to pay the download/decompression price all the time.

Thank you very much for your time.
It’s really clear !

I think I’m running into a similar issue here. I tried using AssetBundle.LoadFromFileAsync but that doesn’t actually cache the file (I check Caching.IsVersionCached immediately after loading the bundle and it always comes back false), so when I next run UnityWebRequest.GetAssetBundle on any bundle that I’d previously loaded from StreamingAssets, it says it’s not cached and re-downloads. Kind of the worst of both worlds (incurring the cost of bundling my assets with my binary and re-downloading them needlessly).

I’ve fixed this on iOS by loading the AssetBundles from StreamingAssets using UnityWebRequest.GetAssetBundle, pointing at Application.streamingAssetsPath (with the file:// protocol). This caches the AssetBundles. However, UnityWebRequest doesn’t like that path on Android.

Is there a way to use AssetBundle.LoadFromFileAsync to cache the AssetBundles it loads, or is there another method I can use to properly load and cache AssetBundles stored in StreamingAssets on both Android and iOS?

I’m using Unity 5.5, for reference.

On Android Application.streamingAssetsPath already includes that ja:file:// protocol, all you need to append the file name to it and it can be loaded using UnityWebRequest.

On Unity 5.5.3p3, that results in an exception, something to the effect of “Unknown” or “Invalid Protocol.”

Oh, right, reading streaming assets using UnityWebRequest was added in 2017.1.

1 Like

Good to know. We’re hoping we can upgrade to 2017.1 but the upgrade process is always a rocky one. Thanks for the follow-up!

We have never managed to get UnityWebRequest and a DownloadHandlerTexture to load files from StreamingAssets on Android, and don’t understand why. This is with Unity 5.6.3f1, but we have tried many other 5.x versions. The same code has always worked fine with WWW, and runs on all platforms other than Android. Note for sanity, we have constructed the path string in two different ways, and checked that filePathPerDocs and filePathFromStreamingAssets are identical.

        // Construct path as recommended in https://docs.unity3d.com/Manual/StreamingAssets.html
        string filePathPerDocs = "jar:file://" + Application.dataPath + "!/assets/" + fileName; 
        Debug.Log("File Path per docs: " + filePathPerDocs);

        // Construct path as we always have for streaming assets.
string filePathFromStreamingAssets = Application.streamingAssetsPath + "/" + fileName; 
        if (Application.platform != RuntimePlatform.Android)
        {
            filePathFromStreamingAssets = "file://" + filePathFromStreamingAssets;
        }
        Debug.Log("File path using streamingassets: " + filePathFromStreamingAssets);

        // Load it. This will fail, but will work if using a WWW.
using (UnityWebRequest www = UnityWebRequest.GetTexture(filePathFromStreamingAssets))

On Android, both of these functions build a string of the form:

jar:file:///data/app/com.mycompany.application-nlg8YQn72iHpXna6k-FeqQ==/base.apk!/assets/imageToLoad.png

And fail with: “A URL Connection to a Java ARchive (JAR) file or an entry in a JAR file is not supported.”

Can somebody tell me what is wrong with this string (e.g. by typing the correct form of the above string)? We have tried all manner of permutations of file://, ///, etc.

Interestingly, this thread implies that UnityWebRequest streamingassets support on Android was only added in 2017.1 (post #16)

Yet there are replies higher in this thread (e.g. #5) saying it works in 5.6.

I see nothing in the 2017.1 release notes saying that android streamingassets support for UnityWebRequest was added in this version. Unity release notes tend to be, umm, opaque but it would be great to clarify.

We tried to do the same.
Ship the apk with embedded initial asset bundles so that the users won’t need to download lots of asset bundles during the startup of the app and also to be able to patch those assets if needed.

However we didn’t succeed to work with the StreamingAssets.
We encountered the following issues:

  1. Error joining threads: 22
    We tried to LoadFromCacheOrDownload from the Application.streamingAssetsPath by going over a list of assets to be load for the first time the app launch (so that later on those assets will be in the cache).
    For simplicity of the POC, we just did this in a for loop with yield return in it on the WWW object.

But we got the “Error joining threads” error.

We did something like this:

var www = [WWW.LoadFromCacheOrDownload(streamingAssetsFile](http://WWW.LoadFromCacheOrDownload(streamingAssetsFile), theHash);
yield return www;
if(!string.IsNullOrEmpty(www.error))
{
Debug.Log(www.error);:wink:
yield return;
}

Any idea what can cause this?

  1. We tried to work with the same code on some popular emulator, such as KoPlayer and we got the following crash:

What we are missing? :frowning:

E/CRASH: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 000000fc
04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: Build fingerprint: ‘SAMSUNG/hlteatt/hlteuc:4.4.4/tt/eng.jenkins.20170104.161952:userdebug/test-keys’
04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: Revision: ‘0’
04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: pid: 17380, tid: 17401, name: UnityMain >>> com.nogame.nogameqa <<<
04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: r0 00000018 r1 95744dcc r2 b850a6e0 r3 b9623730
04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: r4 95744dcc r5 b80bfa90 r6 00000000 r7 00000000
04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: r8 00000000 r9 00000000 sl 00000000 fp 00000000
04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: ip b9623760 sp 95744da0 lr 1610d34c pc 1610d054 cpsr 00000000
04-30 00:22:24.498 17380-17401/com.nogame.nogameqa E/CRASH: backtrace:
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #00 pc 0010d054 /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #01 pc 0010d348 /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #02 pc 00909a2c /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #03 pc 002db184 /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #04 pc 002fbeec /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #05 pc 00524190 /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #06 pc 005275e8 /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #07 pc 17fffffc <unknown/absolute>
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: stack:
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d60 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d64 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d68 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d6c 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d70 8db207a0
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d74 95744d18
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d78 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d7c 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d80 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d84 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d88 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d8c 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d90 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d94 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d98 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744d9c 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #00 95744da0 00000018
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744da4 b80bfa90 [heap]
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744da8 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dac 1610d34c /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #01 95744db0 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744db4 16226e50 /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744db8 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dbc 95744e4c
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dc0 b8515cf0 [heap]
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dc4 00000ac6
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dc8 1a217580 [stack:17398]
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dcc 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dd0 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dd4 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dd8 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744ddc 00000000
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744de0 95744e08
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744de4 16a84c54 /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744de8 95744e10
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: 95744dec 95744e2d
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: … …
04-30 00:22:24.502 17380-17401/com.nogame.nogameqa E/CRASH: #02 95744e70 b850aba0 [heap]
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e74 b9623730 [heap]
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e78 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e7c 162db188 /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: #03 95744e80 00e1b446
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e84 1710fdc8
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e88 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e8c 162fbef0 /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: #04 95744e90 1a217580 [stack:17398]
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e94 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e98 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744e9c 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ea0 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ea4 000000c8
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ea8 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744eac 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744eb0 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744eb4 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744eb8 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ebc 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ec0 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ec4 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ec8 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ecc 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: … …
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: #05 95744ee0 95953350 [anon:libc_malloc]
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ee4 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ee8 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744eec 165275ec /data/app-lib/com.nogame.nogameqa-1/libunity.so
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: #06 95744ef0 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ef4 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ef8 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744efc 18000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: #07 95744f00 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f04 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f08 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f0c 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f10 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f14 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f18 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f1c 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f20 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f24 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f28 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f2c 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f30 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f34 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f38 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744f3c 00000000
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: memory near r1:
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744dac 1610d34c 00000000 16226e50 00000000 L…Pn"…
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744dbc 95744e4c b8515cf0 00000ac6 1a217580 LNt…\Q…u!.
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744dcc 00000000 00000000 00000000 00000000 …
04-30 00:22:24.506 17380-17401/com.nogame.nogameqa E/CRASH: 95744ddc 00000000 95744e08 16a84c54 95744e10 …Nt.TL…Nt.

Which version is that on?