Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Override Unity Data folder path?

Discussion in 'Android' started by zalogic, Nov 21, 2011.

  1. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Hi guys,

    Does anyone know if on Android the Unity Data folder path can be set to some other path before starting the engine?
    By default it searches for the Data folder inside the APK assets/ folder.

    Imagine if I would not want to have the Unity Data folder be placed inside the APK but for example in an application specific folder on the SD card. This would allow me to download the Data folder (in zipped file form) from an external server and bring the application APK to a very low size allowing a great way to overcome the Android Market APK size limit instead of using Asset Bundles to stream assets leading to different issues like the ones described here:
    http://forum.unity3d.com/threads/98105-AssetBundles-memory-overhead

    On the iOS there is a function with which you can do this before starting the engine but I can't seem to find a way to do this on the Android: UnityInitApplication(const char * appPath);

    It would be of huge help to all users that want to reduce APK size to a minimum and store their application data folders for example on an Amazon S3 server so the user will download the APK from the Market and the app resources separately.

    Thank you for any feedback!
     
    Last edited: Nov 21, 2011
  2. colargol

    colargol

    Joined:
    Mar 31, 2010
    Posts:
    65
    With help of Unity team - this is a code for redirecting Unity "download" apk to Unity "data" apk on SD card
    Code (csharp):
    1.  
    2. import android.app.Activity;
    3. import com.unity3d.player.*;
    4.  
    5. public class UnityPlayerActivityMy extends UnityPlayerActivity         //or UnityPlayerProxyActivity ?
    6. {  
    7.         @Override
    8.         public String getPackageCodePath()
    9.         {
    10.              return "/mnt/sdcard/games/GameName.apk";
    11.         }
    12. }
    13.  
     
  3. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    OH MY GOD!!!
    colargol!!!!!! Thank you SOOOOOOOO MUCH! I'm testing this RIGHT now! If this works YOU DON'T realize how much good we will do to the Unity android developers community!

    As soon as I test this I will post the result and then I'll direct this thread to the root of the problem being discussed here:
    http://forum.unity3d.com/threads/111220-How-did-Shadowgun-reduced-APK-to-6-MB
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    So we can pretty much port our iOS games 1:1 with just this line of code, and even resources.load will work?
     
  5. colargol

    colargol

    Joined:
    Mar 31, 2010
    Posts:
    65
    I used this code for one pre-installed deal, in phone memory was small "launching" apk, on SD card normal game apk, and everything worked, Resource.Load either...
    Thanks Floky, that you investigated further on download solution...
     
  6. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Last edited: Nov 22, 2011
  7. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    No hippocoder, but that line of code can help to make a generic installer that we can use to allow us to port iOS games 1:1 no matter the size of the final APK. If it works, i will be able to decouple the unity assets as they are built by unity and download them through this installer on the users SD card. This way the game APK becomes very small and can be uploaded to the Market to be downloaded by any targeted device and the assets can be packed and downloaded by this customizable installer from a 3rd party server until Google will offer free data storage for game assets.

    Let's hope it will work, cause it's still a very big step
    because we get to keep the initial iOS project without needing to hack it with AssetBundles.
     
  8. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    colargol there seems to be something missing.
    I've overriden the package code path (getPackageCodePath() ) to point Unity to some other path on the sdcard but it seems unity also is using another way to search for its libraries cause i'm getting an error when starting the extended UnityPlayerActivity:
    It seems Unity is looking only in the " /mnt/asec/com.unity3d.maze-1/" path for the libs. But this path is ok, i don't need to override the lib path. Something affects the loading of the Unity native libraries.

    I've checked that lib path on the device and it exists, the .so libs are there but it fails to load them for some reason. :(
     
    Last edited: Nov 23, 2011
  9. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    SOLVED!
    There was a stupid problem on my side caused by the fact that Samsung Galaxy S1 has an internal storage memory flash besides the one used for internal phone memory, aaaaaand I also had an SD card plugged in.

    The issue with Android SDK that I haven't figured out yet is that the method Environment.getExternalStorageDirectory( ) was returning the path to the internal storage memory (careful, not the internal phone memory) and NOT the SD card path as expected. So it was trying to load the libs from a path where they didn't exist. They could have thrown a better log message like: "Library not found" or something similar instead of: "JNI_OnLoad returned bad version (0)". :) This log message caused a major confusion.

    I was told that that geting the path to the SD card varies from one device manufacturer to another. Oh well, the issue has been solved.

    So, overriding the getPackageCodePath( ) from the custom activity will in fact redirect the Unity engine to load the libs and the assets from another APK.

    Thank you again colargol.
     
    Last edited: Nov 24, 2011