Search Unity

Android App crashes when loading an AssetBundle from file

Discussion in 'Asset Bundles' started by OfficialMiWo, Feb 11, 2020.

  1. OfficialMiWo

    OfficialMiWo

    Joined:
    Apr 15, 2019
    Posts:
    3
    Hi,

    I have issue with loading a scene from asset bundle.
    I'm currently working with 2019.2.0f1 (because only these version works fine with VR and XR and iL2CPP x64 builds required by app stores)
    Anyways everything works fine while playing in editor.

    assetbundle scene gets downloaded to users/username/AppData/LocalLow/projectname/assetfolderspecificname/assetbundlename.something

    Project is set up for android platform.
    I exported assetbundle for Android specific platform.

    my asset bundle gets downloaded from server to android phone in Application.persistentDataPath
    and assetbundle is found.
    issue is:

    1. When I did use export asset bundle with compression it did have 20mb
    when I didn't use export with compression assetbundle have 9 mb and everything works fine in editor (unity is not pulling nothing from cache from pc.) ??

    2. when I build app and install on android phone it is loading assetbundle but it crashes instantly not showing anything from the scene from asset bundle

    premisions to write sd card are ok and allowed.

    I'm not using WWW method as it is soo F***ing annoying to work with WWW is deprecated use UnityWebRequest as it is full replacement for WWW. IF IT IS FULL REPLACEMENT than Everything should work as WWW. BUT IT Doesn't work, so stop telling that is the same!!
    I'm using these to load scene from asset bundle.


    AssetBundleCreateRequest scenebundle = AssetBundle.LoadFromFileAsync(Path.Combine(Application.persistentDataPath + "/assetfolderspecificname", "assetbundlename.something" ));
    yield return scenebundle;
    AssetBundle Loadedscenebundle = scenebundle.assetBundle;

    SceneManager.LoadScene("scenename");
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    No 1 thing is to make sure you are downloading an asset bundle built specifically for Android. Bundles built for Editor cannot be loaded on Android.

    Then there is stripping. Try disabling "Strip Engine Code" in Player Settings and see, if it works. If your bundle uses engine features that aren't used by any of your scenes, then those features get stripped from build and you run into issues. You need to either have a proper link.xml file or a dummy scene that uses those features (disabling stripping is usually not desired).

    Finally, try looking in logcat, there should be something in there that at least gives a clue for what the exact problem is.

    WWW uses UnityWebRequest under the hood, but some default settings are different, so whatever works with WWW is achievable with UWR (and more). If you provided more details, I could help to sort that part out.
     
  3. OfficialMiWo

    OfficialMiWo

    Joined:
    Apr 15, 2019
    Posts:
    3
    Sry but WWW and UnityWebRequest are not compatible or the same. Please do GET method with header authorization via UnityWebRequest. and do same that thing with WWW class ?

    Anyways, I found reason why is crashing.... ASSETBUNDLE name should be all lowercase START WITH lowercase, no special characters, numbers or Dear God No space. (.extension doesn't matter as long while AssetBundle.LoadFromFileAsync(... // have that extension in the end)

    I made new scene and rename assetbundle IT WORKS FINE no crashes.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Which WWW constructor do you use? Can you show the sample?
    WWW is a wrapper on top of UnityWebRequest, so it's just a matter of passing the parameters correctly.

    Asset bundle file name must match the file name. On case-sensitive file systems it obviously must match case. There is a thing that I believe Unity always creates asset bundle files with lowercased names, even if you use names with some uppercase letter. On Windows you can still load them using original name, since file system is case-insensitive. On Android it is case-sensitive (you'd run into same problem on Linux, OSX, iOS, ...).
    However, the space in name looks buggy, if it's not supported.