Recently we are seeing number of questions scattered around forums regarding build size increase when building iOS applications with Unity 5.3.x. This post aims to clarify some aspects of it in single place.
1. My application build size increased by 130-150 MB after switching to Unity 5.3.x. What’s happening?
We enabled Bitcode support as default for iOS projects. It’s new Apple’s technology, which allows them to re-optimize your application after submission to the App Store. Though it requires to send way more information about your application as part of submission. When your application gets processed by App Store this additional information will be stripped away from your package and won’t increase final download size for your users. This technology is already mandatory for tvOS and watchOS applications, so we are enabling it for iOS to help you prepare ahead of time to make sure that your applications are fully compatible when/if it becomes mandatory for iOS. Description of Bitcode technology is available at: https://developer.apple.com/library/tvos/documentation/IDEs/Conceptual/AppDistributionGuide/AppThinning/AppThinning.html.
2. How can I measure Bitcode size added to my application?
You should make a build of your application, locate where Xcode puts built files and navigate Terminal.app to that folder. Then just run:
otool -l <your_app_name>.app/<your_app_name>[/code]
Inspect its output and look for something like “segname __LLVM”:
cmd LC_SEGMENT
cmdsize 124
segname __LLVM
vmaddr 0x00fac000
vmsize 0x07ce0000
fileoff 15564800
filesize 130940928
The “filesize” attribute is your Bitcode size. Note, if you have build for more than one architecture there could couple of such segments in your app.
3. How can I disable Bitcode for my test builds made by automated build system?
To automate this task we recommend adding Editor build post-processing script:
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
{
if (buildTarget == BuildTarget.iOS)
{
string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
PBXProject proj = new PBXProject();
string nativeTarget = proj.TargetGuidByName(Xcode.PBXProject.GetUnityTargetName());
string testTarget = proj.TargetGuidByName(Xcode.PBXProject.GetUnityTestTargetName());
string[] buildTargets = new string[]{nativeTarget, testTarget};
proj.ReadFromString(File.ReadAllText(projPath));
proj.SetBuildProperty(buildTargets, "ENABLE_BITCODE", "NO");
File.WriteAllText(projPath, proj.WriteToString());
}
}
More example code is available here: https://bitbucket.org/Unity-Technologies/iosnativecodesamples/src/28ca3fca5740f23fb6116855c13c5fdd415ac5d5/NativeIntegration/Misc/UpdateXcodeProject/?at=5.0-dev
4. Testflight download size looks quite bigger that I expected. Any advise on it?
Testflight test build download size does not really represent how much your app will take on actual App Store, because they are going through very different preparation pipelines. It’s not unusual for testflight downloads to be bigger than App Store submission size, because they might include debug symbols and other additional information.
5. Where can I read more on iOS application size analysis?
Please check out this forum post: IL2CPP build size improvements - Unity Engine - Unity Discussions
Edit: added sample code for disabling Bitcode in an automatic way