- Home /
Resource slicing to reduce iOS app size
I am trying to reduce my 80MB iOS app's size. The Android version is only 37MB.
With reference to http://blogs.unity3d.com/2015/12/28/optimizing-ios-app-size-with-resource-slicing/ and http://unity3d.com/learn/tutorials/topics/scripting/assetbundles-and-assetbundle-manager and cannot figure out how to put the two techniques together.
The tutorial require a AssetBundle server to load asset variants. My iOS app is supposed to run offline and I would like to pre-bundle the assets with the app so that the users does not have to connect to some external server to download assets.
However I would like to use "App Slicing" so that iPad's can get a slice of the app with HD textures and the smaller 3.5" and 4" devices get a slice of the app with smaller SD textures. But the iPad should NOT bundle the SD textures and the iPhone should not bundle the HD textures so that each will receive the smallest possible app which is optimized for the specific device.
Is this possible with Unity without an AssetBundle server so that the correct set of assets are pre-bundled (already included in the downloaded app) for a specific device?
Answer by issfire · Jun 28, 2016 at 04:51 AM
Yes, you are looking at App Slicing.
The tutorial is confusing because in effect it's talking about 3 different things:
App Slicing
On Demand Resources (ODR)
Testing App Slicing and ODR Locally
On top of that you also need to have an understanding of Asset Bundles and how Asset Bundles work in Unity.
So what is App Slicing? App Slicing is the process which Unity tells Xcode (and Xcode tells Apple) to generate various app bundle variants for different devices. For example you can tell Apple to create an iPhone App bundle with all your SD assets for 50mb, and tell Apple to create an iPad App Bundle with all your HD assets that total up to be 80mb.
To do this, you must
Label your assets with an SD and HD variant (or any other variant you decide)
During your build process, export your SD, HD Variant Asset Bundles
During your build process, create UnityEditor.iOS.Resources and do .BindVariant, providing the path from (2) and the UnityEditor.iOSDeviceRequirement. UnityEditor.iOSDeviceRequirement is needed to help Apple identify which type of device should use which type of Asset Bundle. When setup correctly, your exported Xcode project will show your asset bundles hooked up in "Assets.xcassets" or Asset catalogs like in this image: http://www.appcoda.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-28-at-9.00.47-PM-1024x239.png
Unity's documentation on this subject is sparse, but understanding how App Slicing works in Xcode will help you understand what Unity is trying to do. This xcode tutorial got me started: http://www.appcoda.com/app-thinning/
What Unity is trying to do is to export Unity's Asset Bundles into Xcode's Asset catalogs.
So why does the AssetBundle demo include a server to load your asset variants? This is more related to On-Demand Resources (ODR) than it is to App Slicing. In App Slicing, the Asset Bundles are pre-downloaded. You simply use AssetBundle.LoadFromFile("res://epic-asset-bundle-name"). Note you omit the variant name ".hd" or ".sd", i.e. you do not load ("res://epic-asset-bundle-name.hd").
When testing ODR, it is useful to simulate the download process directly in Unity.
The two processes, App Slicing and ODR is very similar in Unity's perspective. They both require you to use Asset Bundles. They both require creating UnityEditor.iOS.Resources when building your Xcode project.
The only difference is that in App Slicing the correct Asset Bundles are pre-bundled and comes as a package when the player installs the game.
ODR requires the game client to connect to Apple's server to download the required resources.
Your answer
Follow this Question
Related Questions
Working example of loading scene as asset bundle in Android!? 0 Answers
"Real Memory" usage in iOS expands the more often one prefab is referenced in the assetbundle 0 Answers
Memory overhead associated with assets in Resources 0 Answers
How to export level (map) as an external (non-bundled) asset? 0 Answers
Question about AssetBundles Scripts TextAsset and Reflection in IOS or Android platform 0 Answers