Android APK 大小主要是设计支持库
Android APK Size is mostly the Design Support libraries
所以我制作了一个相对简单的应用程序,几个页面和基本文本 in/out 功能。我正在使用 Xamarin。我的编译代码有几百 KB,但应用程序的总大小(例如 ARM ABI)为 21.7MB,当我打开 APK 时,android 支持库似乎占用了 50%的大小。谁能建议我做错了什么?
这是根视图:
这是程序集文件夹:
默认情况下,Android 中的 Linker
发布模式设置为 Link SDK Only
。您可以通过将 more unused IL
代码设置为 Link All Assemblies
从程序集中删除代码,但请注意,链接器可以工作在静态代码引用上,因此不会看到和删除反射引用的任何代码使用。
您需要确保您正在全面测试您的发布版本是否存在与此相关的错误,并使用各种链接器保存技术(参考:Linking on Android)
Xamarin.Android
Hello World 应用使用 Android.Support.V7
和 Android.Support.V4
Link 仅 SDK
13M ./assemblies
├── [ 2988032] Xamarin.Android.Support.Compat.dll
├── [ 2398208] Xamarin.Android.Support.v7.AppCompat.dll
└── [ 1985024] mscorlib.dll
├── [ 1357312] Mono.Android.dll
├── [ 915456] System.Xml.dll
├── [ 809984] Xamarin.Android.Support.Media.Compat.dll
├── [ 737280] System.dll
├── [ 710656] Xamarin.Android.Support.Core.UI.dll
├── [ 426496] Xamarin.Android.Support.Fragment.dll
├── [ 265216] Xamarin.Android.Support.Core.Utils.dll
├── [ 114176] Xamarin.Android.Support.Vector.Drawable.dll
├── [ 93184] Java.Interop.dll
├── [ 75776] AppV4V7Size.dll
├── [ 49664] Xamarin.Android.Support.Animated.Vector.Drawable.dll
├── [ 37888] Xamarin.Android.Support.v4.dll
├── [ 37888] System.Core.dll
├── [ 11264] System.Runtime.dll
├── [ 5632] System.Runtime.InteropServices.dll
├── [ 5632] System.Reflection.dll
├── [ 5120] System.Threading.dll
├── [ 5120] System.Runtime.Serialization.dll
├── [ 4608] System.Runtime.Extensions.dll
├── [ 4608] System.Reflection.Extensions.dll
├── [ 4608] System.Diagnostics.Debug.dll
├── [ 4608] System.Collections.dll
├── [ 4608] System.Collections.Concurrent.dll
├── [ 4096] System.Linq.dll
Link 所有程序集(节省 9MB...)
3.9M ./assemblies
└── [ 1880576] mscorlib.dll
├── [ 785408] Mono.Android.dll
├── [ 392192] Xamarin.Android.Support.v7.AppCompat.dll
├── [ 222720] System.dll
├── [ 187392] Xamarin.Android.Support.Fragment.dll
├── [ 120320] Xamarin.Android.Support.Compat.dll
├── [ 115712] Xamarin.Android.Support.Media.Compat.dll
├── [ 92160] Java.Interop.dll
├── [ 75776] AppV4V7Size.dll
├── [ 52736] Xamarin.Android.Support.Core.UI.dll
├── [ 39936] Xamarin.Android.Support.Core.Utils.dll
├── [ 37376] System.Core.dll
├── [ 11264] System.Runtime.dll
├── [ 7680] Xamarin.Android.Support.v4.dll
├── [ 5632] System.Runtime.InteropServices.dll
├── [ 5632] System.Reflection.dll
├── [ 5120] Xamarin.Android.Support.Animated.Vector.Drawable.dll
├── [ 5120] System.Threading.dll
├── [ 5120] System.Runtime.Serialization.dll
├── [ 4608] Xamarin.Android.Support.Vector.Drawable.dll
├── [ 4608] System.Runtime.Extensions.dll
├── [ 4608] System.Reflection.Extensions.dll
├── [ 4608] System.Diagnostics.Debug.dll
├── [ 4608] System.Collections.dll
├── [ 4608] System.Collections.Concurrent.dll
├── [ 4096] System.Linq.dll
所以我制作了一个相对简单的应用程序,几个页面和基本文本 in/out 功能。我正在使用 Xamarin。我的编译代码有几百 KB,但应用程序的总大小(例如 ARM ABI)为 21.7MB,当我打开 APK 时,android 支持库似乎占用了 50%的大小。谁能建议我做错了什么?
这是根视图:
这是程序集文件夹:
默认情况下,Android 中的 Linker
发布模式设置为 Link SDK Only
。您可以通过将 more unused IL
代码设置为 Link All Assemblies
从程序集中删除代码,但请注意,链接器可以工作在静态代码引用上,因此不会看到和删除反射引用的任何代码使用。
您需要确保您正在全面测试您的发布版本是否存在与此相关的错误,并使用各种链接器保存技术(参考:Linking on Android)
Xamarin.Android
Hello World 应用使用 Android.Support.V7
和 Android.Support.V4
Link 仅 SDK
13M ./assemblies
├── [ 2988032] Xamarin.Android.Support.Compat.dll
├── [ 2398208] Xamarin.Android.Support.v7.AppCompat.dll
└── [ 1985024] mscorlib.dll
├── [ 1357312] Mono.Android.dll
├── [ 915456] System.Xml.dll
├── [ 809984] Xamarin.Android.Support.Media.Compat.dll
├── [ 737280] System.dll
├── [ 710656] Xamarin.Android.Support.Core.UI.dll
├── [ 426496] Xamarin.Android.Support.Fragment.dll
├── [ 265216] Xamarin.Android.Support.Core.Utils.dll
├── [ 114176] Xamarin.Android.Support.Vector.Drawable.dll
├── [ 93184] Java.Interop.dll
├── [ 75776] AppV4V7Size.dll
├── [ 49664] Xamarin.Android.Support.Animated.Vector.Drawable.dll
├── [ 37888] Xamarin.Android.Support.v4.dll
├── [ 37888] System.Core.dll
├── [ 11264] System.Runtime.dll
├── [ 5632] System.Runtime.InteropServices.dll
├── [ 5632] System.Reflection.dll
├── [ 5120] System.Threading.dll
├── [ 5120] System.Runtime.Serialization.dll
├── [ 4608] System.Runtime.Extensions.dll
├── [ 4608] System.Reflection.Extensions.dll
├── [ 4608] System.Diagnostics.Debug.dll
├── [ 4608] System.Collections.dll
├── [ 4608] System.Collections.Concurrent.dll
├── [ 4096] System.Linq.dll
Link 所有程序集(节省 9MB...)
3.9M ./assemblies
└── [ 1880576] mscorlib.dll
├── [ 785408] Mono.Android.dll
├── [ 392192] Xamarin.Android.Support.v7.AppCompat.dll
├── [ 222720] System.dll
├── [ 187392] Xamarin.Android.Support.Fragment.dll
├── [ 120320] Xamarin.Android.Support.Compat.dll
├── [ 115712] Xamarin.Android.Support.Media.Compat.dll
├── [ 92160] Java.Interop.dll
├── [ 75776] AppV4V7Size.dll
├── [ 52736] Xamarin.Android.Support.Core.UI.dll
├── [ 39936] Xamarin.Android.Support.Core.Utils.dll
├── [ 37376] System.Core.dll
├── [ 11264] System.Runtime.dll
├── [ 7680] Xamarin.Android.Support.v4.dll
├── [ 5632] System.Runtime.InteropServices.dll
├── [ 5632] System.Reflection.dll
├── [ 5120] Xamarin.Android.Support.Animated.Vector.Drawable.dll
├── [ 5120] System.Threading.dll
├── [ 5120] System.Runtime.Serialization.dll
├── [ 4608] Xamarin.Android.Support.Vector.Drawable.dll
├── [ 4608] System.Runtime.Extensions.dll
├── [ 4608] System.Reflection.Extensions.dll
├── [ 4608] System.Diagnostics.Debug.dll
├── [ 4608] System.Collections.dll
├── [ 4608] System.Collections.Concurrent.dll
├── [ 4096] System.Linq.dll