Search Unity

Question File path in IOS and Android for distribution

Discussion in 'Scripting' started by pKallv, Jun 6, 2020.

  1. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    If I want to distribute a file or database with my application, where do I store that?

    I would guess Asset folder but do not really know?
     
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,066
    Regular assets are packed and not accessible separately in builds.

    You want to put them in StreamingAssets, which will just get copied to the build.
     
    pKallv and Kurt-Dekker like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Exactly what @Adrian says above. Here is how to get the path:

    Code (csharp):
    1.     // alas it seems that Unity apparently still requires us to know this...
    2.     // reference: https://docs.unity3d.com/Manual/StreamingAssets.html
    3.     static string StreamingAssetPathForReal()
    4.     {
    5.         #if UNITY_EDITOR
    6.         return "file://" + Application.dataPath + "/StreamingAssets/";
    7.         #elif UNITY_ANDROID
    8.         return "jar:file://" + Application.dataPath + "!/assets/";
    9.         #elif UNITY_IOS
    10.         return "file://" + Application.dataPath + "/Raw/";
    11.         #endif
    12.     }
    NOTE: for Android it is often necessary to open the file as above, then read it and write the data back into a regular file located here:

    https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

    That file will be accessible to things like MySQL that cannot access things through the streaming assets interface. It means that if you have a 50mb database in your APK, you now have to copy it out and write it to another place on the user's phone, requiring yet another 50mb of space, which kinda sucks, but that's what we get for digitally-signed assets like APKs.
     
    sandolkakos and pKallv like this.