user7489552
user7489552

Reputation:

Archived APK file size very huge - Xamarin.Android

After archiving my app, my apk size is 71.82MB (estimated app store size). There are not lot of images also in my application too.

Also, i set my linker to Don't link which is the only option that works for me. It is too big for users. When i set linker to Link SDK assemblies only and also link all assemblies, i get a java exit 1 code error.

Are the some steps i could follow to reduce the size of my apk please?

**Where app crashes **

Environment Variables passed to tool:

    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.

Upvotes: 2

Views: 2193

Answers (2)

Jon Douglas
Jon Douglas

Reputation: 13176

Let's talk about this. There's a few things that end up making your application very large.

1. Mono Linker

Depending on your Linker Behavior set, you can be risking quite a bit of space by not employing a more aggressive linking behavior. That is, if you set your Linker Behavior to None, you are saying "Please include everything inside my application even if it's not used". This can add quite a bit of excess classes/constructors/methods/etc that can bloat an assembly file. This is a managed linker meaning that it will only link your managed code (C#)

See my blog on this:

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

2. CPU Architectures

You might be including too many architectures in your APK than you actually need. With each additional ABI, you are adding quite a bit of bloat to your application.

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

Also see my answer on this here: Which Xamarin ABIs should we support

3. Resources / Raw Files

Large resources and raw files included in your application. Chances are when you're developing your app, you might bring some resources into it. However you might not actually be paying attention to how big some of those resources are. One trick to figure out the main cause of bloat in an APK is to use a tool like WinDirStat(https://windirstat.info/) or Disk Inventory X(http://www.derlien.com/) to investigate why your .apk is so large.

4. Proguard

Finally Proguard can be used as a means to shrink your APK by removing unused classes, fields, methods, and attributes. Think of Proguard as a Native Linker which will optimize your bytecode and remove unused code instructions.

See the documentation I wrote for this here:

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

and

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

RE: Why Proguard is failing

You can see my post on this here:

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

Upvotes: 2

Taier
Taier

Reputation: 2119

Well... that the downside of using Xamarin. It bundles mono runtime and other stuff intro your .apk.

But you have some options:

1) Fix your linking. Yes, that takes time and adds unwanted complexity. But it is what it is, you can't re-write all code back to native.

2) There is an option - "bundle assemblies into native code", from my practice it allows reducing .apk size in half. But it requires enterprise license.

3) Build application only for one instruction set, you can do that under "Android Build -> Advanced" tab. If you want your app to be able to run on all devices, left armeabi. From my experience, you can choose armeabi-v7a, it gives much better performance, and almost all devices nowadays supports it. enter image description here Also, be sure to remove tick from

enter image description here

Even if that does not give any results, while app is under 100mb, you can publish it as it is.

Upvotes: 1

Related Questions