Abstract

We achieved a reduction of 59% on the download and 70% on the footprint sizes for the Unity app “Flipping Blocks” on the iOS platform.

Most of the gain came from moving graphic assets out of the build to asset bundles that are downloaded as needed at runtime.

A small additional gain was achieved by enabling Bitcode.

All numbers in MB.

Measure

Footprint Before

Footprint After

Footprint saving

Download Before

Download After

Download saving

Enable Bitcode

385.0

371.0

14.0

83.6

79.2

4.4

Asset Bundling the graphics

371.0

117.0

254.0

79.2

34.0

45.2

TOTALS

385.0

117.0

268.0

83.6

34.0

49.6

Overview

By far the biggest problem for the footprint (the amount of space the app takes up in the iPhone’s storage) is the graphics files.

The PNG files get expanded to their full size (about 20 time bigger than compressed). On Android it seems the graphics assets are expanded for use when the app is actually activated, whereas on iOS the app is completely unpacked on installation and takes up an inordinate amount of room on your disk. At least this is the story our phones are telling us.

You can see how big the graphics files are by checking the build log after making a build. On OS X you will find the build log under ~/Library/Logs/Unity/Editor.log. Look for “Textures” or “Complete size”. This is what I currently see in my log (I’ve already done some optimization so textures now take “only” 92% of the space compared to the previous 97%):

If you want to see for yourself where your app is using up space, unpack your IPA file

$ unzip Unity-iPhone.ipa

You will find giant files called resources.assets and resources.assets.resS in the directory Payload/yourappname.app/Data/. I believe that the resS file is created from files that are assigned to asset bundles. All of the graphic assets used by your app are in these files, in fully expanded, uncompressed form. The reasoning is probably that concatenating the contents of multiple files and compressing the result gets you a better compression result than compressing the files individually.

Asset Bundles

I assigned our language specific graphics to asset bundles. Asset bundles have to built separately for each platform. You cannot use Android asset bundles with iOS. The asset bundles are kept on a web server and downloaded as needed by the app. Logic has to be written to handle this, especially if your code depends on Resources.Load. More about this in my previous post dealing with asset bundles for the Android version of the game.

You have to prevent any files that have been assigned to asset bundles getting into the build. My Android trick of making the asset bundled files unreadable by removing their read permissions didn’t work. This just causes Unity to hang. You have to move the files out of their Resources directory to a place where the build cannot find them. I did this by creating a temporary directory called “language_tmp” next to my Assets directory and moving the language files there before starting the build.
$ mkdir -p language_tmp
$ mv Assets/Resources/language/{de,es,fr,it,ja,zh} language_tmp/

Once those files are out of the way the resources.assets and resources.assets.resS are much smaller.

The reason for these tricks is that Unity automatically puts everything from Resources folders into the build, no questions asked. For historical reasons all my graphics files are in Resources folders. If you can avoid doing this, do so.

The download size of the app was reduced by this measure from 79.2 MB to 34 MB. The footprint went from 371 MB to 117 MB, a massive reduction of 254 MB!

Bitcode

We also got a small win by enabling Bitcode in Xcode. This makes it possible for Apple to build device specific downloads of your app. This reduced the footprint by about 14MB and the download size by 4.4MB. Enabling bitcode will make a big proportional difference if your app is not graphics heavy. Every little bit helps.

There is still room for improvement. I have kept the English language assets in the IPA because then at least something pretty is available should you go offline immediately after download. It might be worth asset bundling those too. Most of our buttons are graphic rather than text because we were not able to achieve our curvy font effects in uGUI with conventional means. If anybody knows how to get those effects using text only then please let me know!