1

In android studio's build.gradle file,we can use shrinkresources set to true to shrinkify our app.Also can use minifyenabled and proguard options as well.

But in xamarin, How can I use these options?

I use proguard in my app as it referred in xamarin doc.but didn't find any use of it (I mean my app size didn't get reduced).My simple app is having around 18Mb in size.If anyone have experience using proguard in xamarin,please paste a sample file here also explain how you accomplished this.So others can also benefited.

Habel Philip
  • 205
  • 3
  • 10
  • I do not have experience with Proguard (because I could never get it to work and could not find any helpful documentation) but I do have experience with the Linker. Do you have that turned on? Android Project -> Properties -> Android Options -> Linker – hvaughan3 Jun 13 '16 at 14:54
  • bjut these methods won't reduce app size like in android studio – Riyas PK Jul 29 '16 at 08:53
  • you can open apk file using a zip explorer and check which files use most of the spaces.also building different apk for each architecture reduce app size for a small extent @riyas-pk – Habel Philip Jul 29 '16 at 17:52

2 Answers2

1

Proguard only can reduce an APK size if it contains a large number of unused classes (e.g. included because of libraries). Therefore it can only reduce the size of the classes.dex file in your APK. However an APK usually contains a large number of other files - they will not be touched by Proguard.

You should open the generated APK file in a ZIP viewer and see what elements take the space. If it is the classes.dex file it is only a matter of Proguard configuration.

Robert
  • 39,162
  • 17
  • 99
  • 152
1

I know you're asking specifically about the proguard and minifyenabled features of Android Studio but if the intent is specifically to reduce the size of your application, you should configure a more aggressive linking strategy.

  1. Right click android project
  2. Under "Build" select "Android Build" (or "iOS Build")
  3. Select "Link All" for "Linker behavior" dropdown

Make sure this is only for Release or Ad-Hoc configurations, depending on your distribution strategy.

Linker Configuration Workflow:

  1. Run app on a physical device for desired configuration (Release/Ad-Hoc)
  2. Test functionality until "TypeInitializationException" or similar exception occurs
  3. Add the type/field/method to the configuration file
  4. Rinse and repeat until the application is stable

If you don't like the configuration file, you can also use the PreserveAttribute. If the linker is stripping out classes in one of your PCLs that don't have access to this attribute, you can define your own attribute in that PCL called PreserverAttribute because the linker is just looking for an attribute with that name, not necessary of a specific type.

The linker works by analyzing code paths and removing what it believes to be unused references. If you use dependency injection, the linker won't understand which references it needs to keep around so this can take some time but it can drastically reduce the size of your application and you only need to do it once. You can follow the same steps above for iOS as well.

Bonus Make sure "Strip native debugging symbols" is checked in the build options. Its set by default but some disgruntled coworker could have unchecked it.

Additional Resources:
Linking on iOS

Linking on Android

pfluggs11
  • 166
  • 2
  • 9