Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce the package size

I have implemented an Android application using Xamarin:

The size of the .apk is 13.6MB with:

  • Configuration: Release
  • Linking: Sdk Assemblies Only
  • Suported architectures: armeabi,armeabi-v7a

Here is the overview of sizes of the main components taken from the compiled .apk:

(these are the uncompressed sizes, I unarchived the .apk to a directory and looked to the files in Windows Explorer):

  • classes.dex (1.23 KB)
  • the two libmonodroid.iso (armeabi + armeabi-v7a) (5.58 MB)
  • all Mono.xxx.dll (3.89 MB)
  • mscorlib.dll (1.51 MB)
  • all System.xxx.dll (2.56 MB)

  • My app assemblies (the Droid app + one PCL) (204 KB)

  • MvvmCross + plugins (599 KB)
  • Xamarin ActionbarSherlock (348 KB)
  • ZXing.monoandroid (413 KB)
  • PCL Newtonsoft.Json (398 KB)
  • PCL Microsoft HTTP Client libraries (System.Net.Http.dll) (110KB)

  • 'res' folder (Size: 451KB Size on disk: 816KB) - because some files are 1KB they produce fragmentation, so Actual size vs Size on disk is significantly different

  • all PNG files (Size: 325KB Size on Disk: 496KB on disk)

What can I do in order to reduce the size of the compiled .apk?

I find it pretty big.

like image 440
WriteEatSleepRepeat Avatar asked Nov 02 '22 09:11

WriteEatSleepRepeat


1 Answers

Use linking: Sdk + User Assemblies, and go through the difficult process of marking classes with the Preserve attribute (see http://docs.xamarin.com/guides/ios/advanced_topics/linker/). You can check which class is missing when your app crashes in the android log. It should be only the classes used dynamically by reflection or using an IoC.

You can also create 2 separate packages, one with armeabi only (for very old devices), one with armeabiv7a, and one with x86 (currently your app will just crash on x86 android devices). Google play supports having 3 separate packages with different capabilities (don"t forget to change the capabilities in your manifest file for each package)

like image 185
Softlion Avatar answered Nov 15 '22 04:11

Softlion