Unity - How can I handle large Android apps

March 22, 2014 - 8:53am #1

If you are building an application with the Vuforia Unity Extension, and you application size exceeds 50MB, you may need to take some special measures in order to be ble to publish this on the Google Play Store, due to the Google Play 50MB app requirement as explained in the official Google Android web site here:

http://developer.android.com/google/play/expansion-files.html

General tips and suggestions

Hosting assets on a server and downloading at runtime 

If the size of your App is due to the use of large files, such as videos and/or large 3D models and textures or other large Unity assets, you may want to consider placing those assets onto an external location, such as a server, and download and use the contents through the network at runtime. This way, you can dramatically reduce your App size, as the heavy-weight / large assets are not packaged with the App.

Asset Bundles

Note that Unity also provides a convenient feature and API to achieve this, called Asset Bundles. Please refer to the official Unity Asset Bundle documentation for more details about this feature:

https://docs.unity3d.com/Documentation/Manual/AssetBundlesIntro.html

If you choose to go with this approach, you may also be interested in reading this article about how to dynamically create 3D augmentations for Vuforia Image Targets using Asset Bundles:

https://developer.vuforia.com/forum/faq/unity-how-can-i-augment-my-image-target-model 

 

Using OBB expansion files

Another possibility is to use the OBB explansion files, which practically allow your App to go beying the 50MB limit, by using the Split Application Binary option in the Player Settings, spliting it into an APK + an expansion file (.obb), as explained in the Unity online documentation:

https://docs.unity3d.com/Documentation/Manual/android-OBBsupport.html

OBB and Vuforia

While you are allowed to use the OBB split option with Vuforia, you should be aware that certain Vuforia functionalities may not be fully available and may need to be handled in a special way.

In particular, the Dataset loading feature may be affected, as the dataset files (.DAT and .XML) that you have placed in the 'Assets/StreamingAssets/QCAR' folder in your Unity project, will likely get stored on the OBB expansion file. As a consequence, the Dataset load methods of the Vuforia API may fail to locate and load those files correctly.

In order to properly handle this scenario, you will need to follow these steps:

  • make sure that the desired Datasets to load are "enabled" in the Data Set Load Behaviour of the ARCamera
    • for each Dataset, enable (tick) the 'Load Data Set Your_Dataset_Name' and 'Activate Dataset Your_Dataset_Name' check-boxes via the ARCamera inspector
  • create a C# script to programmatically read your Dataset XML and DAT files from these locations:
    • Application.streamingAssetsPath + "/QCAR/" + dataset_xml_filename / dataset_dat_filename
    • Application.applicationDataPath + ''/Android/obb/" + obb_filename (check the Android developer guide for more information on the actual OBB path and filename: http://developer.android.com/google/play/expansion-files.html)
  • read the .DAT and .XML files, for instance using the www class with a URI pointing to one of the locations above (see also: https://docs.unity3d.com/Documentation/ScriptReference/WWW.html)
  • get the files content (as a byte array) from the www class, using the www.bytes method
  • save the files content into a new pair of .DAT and .XML files on your device storage (e.g. your SD card, or otherwise to a device internal storage); for instance, store them onto a subdirectory of Application.persistentDataPath (e.g. Application.persistentDataPath + "/MyDatasets/MyDataset.xml" and Application.persistentDataPath + "/MyDatasets/MyDataset.dat")
  • use the Vuforia API to load the datasets from the new location, using the STORAGE_ABSOLUTE option, as shown in this code example:

 

 

 

 

Topic locked