Xamarin - apk 应用程序大小 [英] Xamarin - apk App Size

查看:24
本文介绍了Xamarin - apk 应用程序大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,在使用 Xamarin.Forms 开发应用程序之后,当我今天尝试创建发布版本时,我震惊地看到应用程序大小为 ~25MB - ~31MB(在 SDK Only Linking 之后,ProGuard, 为每个 abi 创建 apk).我的资源文件夹仅以 KB 为单位.在调试模式下,apk 实际上只有 5MB,很高兴看到它.后来我意识到这是因为我们不应该在发布模式下使用使用共享运行时"选项.

然后我尝试创建一个空白的 Xamarin.Android 应用程序,但使用 Linking SDK &用户程序集、ProGuard、每个 abi 的 APK 仍然是 ~8MB 到 ~13MB.

根据以下链接,Hello World 应用程序的最小大小为 2.9MB,但是我无法创建这样的大小.

在最近的一次 Microsoft 技术会议上,我碰巧知道9 News"应用程序(下面的链接)是使用 xamarin 构建的,并且创作者都在舞台上.然而,我对它的应用程序大小感到惊讶.它只有 5.85 MB.我不确定这是如何实现的?

谁能帮我解决这些问题?

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 SDK Only Linking, ProGuard, Creating apk for each abi). My resource folder is only in KBs. The apk actually was just 5MB in debug mode and was so happy to see it. I later realized that this is because of the option "Use Shared Runtime" which we are not supposed to use in Release Mode.

I then tried creating a blank Xamarin.Android app, but the release build with Linking SDK & User Assemblies, ProGuard, APK for each abi is still ~8MB to ~13MB.

Per the below link the minimum size is 2.9MB with the Hello World app, however I am unable to create such size. https://developer.xamarin.com/guides/android/advanced_topics/application_package_sizes/

For my app and the blank app I created, the necessary dlls seem to be high (example mscorlib.dll is 2.2mb etc, where as the link says after linking it will become 1 mb) Here is what I see as my assembly folder after extracting the apk

In one of the recent Microsoft tech conferences I happened to know that "9 News" app (link below) was built using xamarin, and the creators were present on the stage. However I was surprised with it's app size. It is only 5.85 MB. I am unsure how that is achieved?

Can any one help me with these?

https://play.google.com/store/apps/details?id=nineNewsAlerts.nine.com

I am also curious to know if Microsoft doing something to improve app package sizes? Or will this be resolved if they bring .NET core to xamarin?

解决方案

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:

这篇关于Xamarin - apk 应用程序大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆