iOS Stripping Level
The size optimizations activated by stripping work in the following way:
- Strip assemblies level: the scripts’ bytecode is analyzed so that classes and methods that are not referenced from the scripts can be removed from the DLLs and thereby excluded from the AOT compilation phase. This optimization reduces the size of the main binary and accompanying DLLs and is safe as long as no reflection is used.
- Strip ByteCode level: any .NET DLLs (stored in the Data folder) are stripped down to metadata only. This is possible because all the code is already precompiled during the AOT phase and linked into the main binary.
- Use micro mscorlib level: a special, smaller version of mscorlib is used. Some components are removed from this library, for example, Security, Reflection.Emit, Remoting, non Gregorian calendars, etc. Also, interdependencies between internal components are minimized. This optimization reduces the main binary and mscorlib.dll size but it is not compatible with some System and System.Xml assembly classes, so use it with care.
These levels are cumulative, so level 3 optimization implicitly includes levels 2 and 1, while level 2 optimization includes level 1.
Stripping with IL2CPP
The equivalent of Strip ByteCode is always enabled when the IL2CPP scripting backend is used. In this case, the Stripping Level option is replaced with an Boolean option named Strip Engine Code. If this option is enabled, unused modules and classes in the Unity Engine code will be removed, if it is disabled, all of the modules and classes in the Unity Engine code will be preserved.
Simple Checklist for Making Your Distribution as Small as Possible
- Minimize your assets: enable PVRTC compression for textures and reduce their resolution as far as possible. Also, minimize the number of uncompressed sounds. There are some additional tips for file size reduction here.
- Set the iOS Stripping Level to Use micro mscorlib.
- Set the script call optimization level to Fast but no exceptions.
- Don’t use anything that lives in System.dll or System.Xml.dll in your code. These libraries are not compatible with micro mscorlib.
- Remove unnecessary code dependencies.
- Set the API Compatibility Level to .Net 2.0 subset. Note that .Net 2.0 subset has limited compatibility with other libraries.
- Don’t use JS Arrays.
- Avoid generic containers in combination with value types, including structs.
How small can an app be made with Unity?
An empty project would take less than 22 MB in the App Store if all the size optimizations were turned off. With code stripping, the empty scene with just the main camera can be reduced to less than 12 MB in the App Store (zipped and DRM attached).
Why did my app increase in size after being released to the App Store?
When publishing your app, Apple App Store service first encrypts the binary file and then compresses it via zip. Encryption increases ’‘randomness’ of the code segment and thus makes it worse for compression. Check “Building for distribution” chapter above how to estimate App Store size before submission.