Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Xamarin Reduce App Size
* Reducing executable size:,_testing,_and_metrics/memory_perf_best_practices/#Reducing_Executable_Size
* Use the linker (iOS [1], Android [2]) to remove unnecessary code from your assemblies
* Reference third-party libraries judiciously
* Applying constraints to generics may reduce app size, since less code would need to be included (haven’t verified this)
Make sure you are only building the project for the required architectures. For instance, on iOS [3] you may not need both ARMv7s and ARMv7 (though you’ll need to consider that since I don’t know your use case completely). On Android, you can similarly limit the ABIs [4] (more info [5]) that the app is build for, or build one APK for each required architecture [6].
* Use app thinning / slicing [7] to deliver only the binaries required on iOS
* Download assets / levels / resources at runtime (Apple’s On-Demand Resources feature [8] in iOS 9 can facilitate this)
*Does your iOS app include many space-consuming icons/image assets (@1x, @2x, @3x) that could be drawn instead of rendered as images? Use PaintCode [9] to translate vector files into code snippets that draw the assets accurately, at any size desired. This can be a great help in reducing app size, as you don’t have to include as many large image assets. Of course, it can’t be used to draw photos, so its uses are limited.
* Limit your use of structs, as they can increase compiled code size
* Limit your use of generics, as they can increase compiled code size (more info about generics can be found here, on Stack Overflow [10]
* Disabling LLVM on iOS may shrink the build a small amount
* It may be possible to use a Jetpack to help reduce app size
* There’s a point here [11] about linking to Mono as an extension: “One scenario for linking with the Mono runtime as a framework even for apps without extensions is to decrease the executable size, to overcome any size restrictions Apple enforces on the executable. For reference, the Mono runtime adds approximately 1.7MB per architecture (as of Xamarin.iOS 8.12, however his varies between releases, and even between apps). The Mono framework adds approximately 2.3MB per architecture, which means that for a single-architecture app without any extensions, making the app link with the Mono runtime as a framework will shrink the executable by ~1.7MB, but add a ~2.3MB framework, resulting in a ~0.6MB bigger app altogether.”
* To get a best guess at app size for an iOS app, create a build for a single architecture, archive it, and look at the “Estimated App Store Size” in the Archives section of Xamarin Studio
** Note that (as of December 2015) looking at the “Estimated App Store Size” in the Archives section of Xamarin Studio does not include App Thinning
** Look at the size of the .ipa or .xcarchive directly is misleading
* Basic "empty" iOS app sizes may change, but here they are as of early December 2015:
** An empty, traditional Xamarin iOS (non-Xamarin.Forms) app that is about 4.01mb in size (Estimated App Store Size)
** An empty Xamarin.Forms 2.0 iOS app is about 16.4mb (Estimated App Store Size)
** For both of these apps, I used the following settings: LLVM enabled, Thumb–2 enabled, strip native debug symbols enabled, linker set to “Link All,” supported architectures: ARMv7 only
** Need to collect Android info here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment