存档的APK文件非常庞大 - Xamarin.Android

时间:2017-07-17 14:43:23

标签: c# android xamarin xamarin.android

归档我的应用后,我的apk大小为71.82MB(估计应用商店大小)。我的应用程序中也没有很多图像。

另外,我将链接器设置为不链接,这是唯一适用于我的选项。这对用户来说太大了。当我将链接器设置为仅链接SDK程序集并链接所有程序集时,我得到一个java退出1代码错误。

我可以遵循的一些步骤来减少我的apk尺寸吗?

** app崩溃的地方**

环境变量传递给工具:

    PROGUARD_HOME=/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/proguard
    /usr/bin/java -jar /Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/proguard/lib/proguard.jar -include /Users/emmnock/AndroidStudioProjects/android-sdk-macosx//tools/proguard/proguard-android.txt -include obj/Release/proguard/proguard_xamarin.cfg -include obj/Release/proguard/proguard_project_references.cfg -include obj/Release/proguard/proguard_project_primary.cfg -include proguard.cfg -include obj/Release/XbdMerge/proguard/00d975c90.txt -include obj/Release/XbdMerge/proguard/0757626b0.txt -include obj/Release/XbdMerge/proguard/1db418320.txt -include obj/Release/XbdMerge/proguard/1f4fd9cc0.txt -include obj/Release/XbdMerge/proguard/211c61910.txt -include obj/Release/XbdMerge/proguard/2f4d086a0.txt -include obj/Release/XbdMerge/proguard/581878c90.txt -include obj/Release/XbdMerge/proguard/67b1d0a90.txt -include obj/Release/XbdMerge/proguard/8f1de9cb0.txt -include obj/Release/XbdMerge/proguard/a35ed7280.txt -include obj/Release/XbdMerge/proguard/acdd43380.txt -include obj/Release/XbdMerge/proguard/b76e0d310.txt -include obj/Release/XbdMerge/proguard/c756521f0.txt -include obj/Release/XbdMerge/proguard/d87effcf0.txt -include obj/Release/XbdMerge/proguard/d99a9fda0.txt -include obj/Release/XbdMerge/proguard/d9f2c52f0.txt -include obj/Release/XbdMerge/proguard/dc663e480.txt -include obj/Release/XbdMerge/proguard/e5bf18810.txt -include obj/Release/XbdMerge/proguard/e843ef2a0.txt -include obj/Release/XbdMerge/proguard/fb4df8d50.txt "-injars 'obj/Release/proguard/__proguard_input__.jar':'/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v7.1/mono.android.jar':'/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/android-support-multidex.jar':'obj/Release/__library_projects__/Bolts.AppLinks/library_project_imports/bin/classes.jar':'obj/Release/__library_projects__/Bolts.Tasks/library_project_imports/bolts-tasks.jar':'obj/Release/__library_projects__/EasySplashScreen/library_project_imports/bin/classes.jar':'obj/Release/__library_projects__/ExoPlayer/library_project_imports/bin/classes.jar':'obj/Release/__library_projects__/FormsViewGroup/library_project_imports/formsviewgroup.jar':'obj/Release/__library_projects__/Glide/library_project_imports/glide-3.8.0.jar':'obj/Release/__library_projects__/Refractored.Controls.CircleImageView/library_project_imports/bin/classes.jar':'obj/Release/__library_projects__/Square.OkHttp/library_project_imports/okhttp.jar':'obj/Release/__library_projects__/Square.OkIO/library_project_imports/okio.jar':'obj/Release/__library_projects__/Square.Picasso/library_project_imports/picasso-2.5.2.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.Animated.Vector.Drawable/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.Compat/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.Core.UI/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.Core.Utils/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.CustomTabs/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.Design/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.Fragment/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.Media.Compat/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.Transition/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.Vector.Drawable/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.v4/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.v7.AppCompat/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.v7.CardView/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.v7.MediaRouter/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.v7.Palette/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Android.Support.v7.RecyclerView/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Facebook/library_project_imports/bin/classes.jar':'obj/Release/__library_projects__/Xamarin.Facebook.AudienceNetwork/library_project_imports/bin/classes.jar':'obj/Release/__library_projects__/Xamarin.Firebase.Analytics/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Firebase.Analytics.Impl/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Firebase.Auth/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Firebase.Common/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Firebase.Database/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Firebase.Database.Connection/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Firebase.Iid/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Firebase.Storage/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.Firebase.Storage.Common/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.GooglePlayServices.Ads/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.GooglePlayServices.Ads.Lite/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.GooglePlayServices.Base/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.GooglePlayServices.Basement/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.GooglePlayServices.Clearcut/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.GooglePlayServices.Gass/library_project_imports/classes.jar':'obj/Release/__library_projects__/Xamarin.GooglePlayServices.Tasks/library_project_imports/classes.jar'" "-libraryjars '/Users/emmnock/AndroidStudioProjects/android-sdk-macosx/platforms/android-25/android.jar'" -outjars "obj/Release/proguard/__proguard_output__.jar" -optimizations !code/allocation/variable 
    proguard.ParseException: Unknown option '' in line 1 of file 'proguard.cfg',
      included from argument number 10
        at proguard.ConfigurationParser.parse(Unknown Source)
        at proguard.ProGuard.main(Unknown Source)
    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1922,3): error MSB6006: "java" exited with code 1.
  Done executing task "Proguard" -- FAILED.
Done building target "_CompileToDalvikWithDx" in project "FindMeApp.Droid.csproj" -- FAILED.

Done building project "FindMeApp.Droid.csproj" -- FAILED.

2 个答案:

答案 0 :(得分:1)

嗯......使用Xamarin的缺点。它捆绑了单声道运行时和其他东西介绍你的.apk。

但你有一些选择:

1)修复链接。是的,这需要时间并增加了不必要的复杂性。但事实就是如此,你无法将所有代码重新写回原生代码。

2)有一个选项 - “将程序集捆绑成本机代码”,从我的实践中它可以将.apk大小减少一半。但它需要企业许可证。

3)仅为一个指令集构建应用程序,您可以在“Android Build - > Advanced”选项卡下执行此操作。如果您希望自己的应用能够在所有设备上运行,请离开 armeabi 。根据我的经验,您可以选择 armeabi-v7a ,它可以提供更好的性能,现在几乎所有设备都支持它。 enter image description here 另外,请务必从

中删除勾号

enter image description here

即使没有给出任何结果,当应用程序低于100mb时,您可以按原样发布它。

答案 1 :(得分:1)

我们来谈谈这个。有一些东西最终会使你的应用程序变得非常大。

<强> 1。单声道连接器

根据您的链接器行为设置,如果不采用更具侵略性的链接行为,您可能会冒很大的空间。也就是说,如果您将链接器行为设置为None,则表示“请将我的应用程序中的所有内容包括在内,即使它未被使用”。这可能会添加相当多的多余的类/构造函数/方法/等,这些类可能会使程序集文件膨胀。这是托管链接器,这意味着仅链接您的托管代码(C#)

请参阅我的博客:

http://www.jon-douglas.com/2017/04/13/linker-bitdiffer/

<强> 2。 CPU架构

您可能在APK中包含的实际架构太多,而不是实际需要的架构。每增加一个ABI,您就会在应用程序中添加相当多的膨胀。

https://developer.xamarin.com/guides/android/application_fundamentals/cpu_architectures/#How_to_Specify_Supported_Architectures

另请参阅我的答案:Which Xamarin ABIs should we support

第3。资源/原始文件

您的应用程序中包含大量资源和原始文件。有可能在您开发应用程序时,您可能会带来一些资源。但是,您可能实际上并没有注意到这些资源有多大。找出APK中膨胀的主要原因的一个技巧是使用WinDirStat(https://windirstat.info/)或磁盘清单X(http://www.derlien.com/)之类的工具来调查你的.apk如此之大的原因。

<强> 4。 Proguard的

最后,通过删除未使用的类,字段,方法和属性,可以将Proguard用作缩小APK的方法。将Proguard视为原生链接器,它将优化您的字节码并删除未使用的代码指令。

请参阅我为此撰写的文档:

http://www.jon-douglas.com/2016/11/22/xamarin-android-proguard/

https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/proguard/#Overview

RE:为什么Proguard失败

你可以在这里看到我的帖子:

Xamarin proguard.ParseException: Unknown option '' in line 1 of file 'Properties/proguard.cfg'