Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Xamarin Reduce App Size
* Reducing executable size:
http://developer.xamarin.com/guides/cross-platform/deployment,_testing,_and_metrics/memory_perf_best_practices/#Reducing_Executable_Size
* Use the linker (iOS [1], Android [2]) to remove unnecessary code from your assemblies
[1] https://developer.xamarin.com/guides/ios/advanced_topics/linker
[2] https://developer.xamarin.com/guides/android/advanced_topics/linking
* 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].
[3] https://developer.xamarin.com/guides/ios/advanced_topics/compiling_for_different_devices/
[4] http://developer.android.com/intl/zh-cn/ndk/guides/abis.html
[5] https://developer.xamarin.com/guides/android/advanced_topics/MultiCore_devices_XamarinAndroid/
[6] https://developer.xamarin.com/guides/android/advanced_topics/build-abi-specific-apks/
* Use app thinning / slicing [7] to deliver only the binaries required on iOS
[7] https://developer.apple.com/library/tvos/documentation/IDEs/Conceptual/AppDistributionGuide/AppThinning/AppThinning.html
* Download assets / levels / resources at runtime (Apple’s On-Demand Resources feature [8] in iOS 9 can facilitate this)
[8] https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/On_Demand_Resources_Guide/
*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.
[9] http://www.paintcodeapp.com/
* 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]
[10] http://stackoverflow.com/questions/31481844/disable-generics-in-c-sharp-for-xamarin
* 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.”
[11] http://developer.xamarin.com/guides/ios/advanced_topics/embedded_frameworks/
* 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