Search Unity

Bug UnityWebRequest to StreamingAssetsPath returns 404 Not Found

Discussion in 'Android' started by justdizzy, Jun 3, 2023.

  1. justdizzy

    justdizzy

    Joined:
    Mar 8, 2016
    Posts:
    89
    I recently upgraded a rather large Android project to Unity 2021.3.25 (Apple Silicon), I have both Build Settings' "Build App Bundle" and Publish Settings' "Split Application Binary" checked generating a 500+ MB AAB file, and I am trying to access the files in StreamingAssets folder via UnityWebRequest as per documentation, but it is returning an HTTP 404

    Code (CSharp):
    1. string path = Path.Combine(Application.streamingAssetsPath, localHTMLFilename);
    2. // jar:file:///data/app/com.mycom.myapp-pjfyG71knFzfDkJzXNNHSg==/split_UnityDataAssetPack.apk!/assets/HTMLs/index-android.html
    3. UnityWebRequest www = UnityWebRequest.Get(path);
    4. yield return www.SendWebRequest();
    5. Debug.Log($"www result: {www.responseCode}: {www.error}");
    6. // www result: 404: HTTP/1.1 404 Not Found
    Shouldn't this work? Is this complicated because of having both options checked? Are there any special permissions I need to make sure are requested when doing this? The files are in the SteamingAssets folder of the project, is there another method to verify that they are installed in app correctly?
     
  2. justdizzy

    justdizzy

    Joined:
    Mar 8, 2016
    Posts:
    89
    UPDATE:
    1. I unzipped the AAB (actually it's 1.5GB, yay videos!), and the HTMLs folder and files are present in UnityStreamingAssetsPack/assets/ folder.
    2. If I uncheck "Split Application Binary", the code above works properly with no other changes, so the issue seems to be either I can't access that folder. FYI the new path is: jar:file:///data/app/com.mycom.myapp-_yiJkJdETNBdUn1lZw_Jxw==/base.apk!/assets/HTMLs/index-android.html
     
  3. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    393
    Maybe UnityStreamingAssetsPack is set to fast-follow delivery mode as the documentation said:
    If it's the case, you can use APIs (mentioned in the documentation above) to wait the asset pack to be downloaded before accessing files in it.
     
  4. justdizzy

    justdizzy

    Joined:
    Mar 8, 2016
    Posts:
    89
    That is a good point for an install from the Google Play store, but this is the direct install from Unity Editor on to device, so that should not be the issue.
    I note that the streaming assets path contains "...==/split_UnityDataAssetPack.apk!/assets/..." but in the AAB there are separate folders UnityStreamingAssetsPack and UnityDataAssetsPack, so it seems like the path is incorrect. I did try manually replacing the section in the path, but that did not work either.
     
  5. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    393
    I assumed you're talking Unity's Build and Run. I'm not sure about its behaviour, but I found a documentation about Google Play Plugins for Unity:
    Maybe Unity's behaviour is the same.

    I implemeted custom asset packs in our project and noticed the name of asset pack was not important to load the asset inside the asset pack. I can use Path.Combine(Application.streamingAssetsPath, fileName) to load asset inside my custom install-time asset pack without any problem. (I was using Unity 2020.3.47)
     
    Last edited: Jun 6, 2023
  6. QingRuoChen

    QingRuoChen

    Joined:
    Jan 17, 2013
    Posts:
    4
    When I build with IL2CPP, it seems that I can read to the file in StreamingAssets