Xamarin - apk App Size

前端 未结 3 1143
小蘑菇
小蘑菇 2020-12-08 11:32

So, after all the hard-work developing the app using Xamarin.Forms, when I tried to create a release build today, I was shocked to see the app size is ~25MB - ~31MB (after S

3条回答
  •  有刺的猬
    2020-12-08 11:49

    Xamarin Android APK files have a larger size than usual because they include the Xamarin libraries, that translate C# code to Java code, to run in Android OS.

    Using the following options, you can reduce the APK size:

    • Configuration: Active (Release).
    • Platform: Active (Any CPU). These are necessary to build your APK for the Google Play Store.
    • Use Shared Runtime: false. If you set it to true, the APK will use Mono Runtime to execute. The Mono Runtime is installed automatically when debugging through USB, but not in the Release APK. If Mono Runtime is not installed in the device and this option is set to true in the Release APK, the app will crash.
    • Generate one package (.apk) per selected ABI: false. Create your APK for as many platforms as possible, for compatibility reasons.
    • Enable Multi-Dex: true, but you can set it to false if your app is not very complex (that is, has less than 65536 variables or methods, see here).
    • Enable developer instrumentation (debugging and profiling): false for Release APK.
    • Linking: SDK and User Assemblies. This will make the Xamarin compiler to remove all unused classes from SDK and your code, reducing the APK size.
    • Supported architectures: Select all, for compatibility reasons.

    Here is a print screen example:

提交回复
热议问题