Techniques for Optimizing and Reducing Android Apps size in Xamarin

Techniques for Optimizing and Reducing Android Apps size in Xamarin

As mobile app development gains popularity, enterprises are investing more in developing applications. However, developing a mobile application is not an easy process and it involves a lot of time, especially if you want a scalable mobile app, which runs across Apple, Android, and Windows.

As the spread of development platforms widens, we need the right tool and approach to meet the increasing demands. Xamarin is one such framework that enables a single codebase to be shared over Android, iOS and Windows Platforms. The popularity of this framework is rapidly increasing as it saves the development time by catering to all platforms. 

Here are a few tips on how we can optimize Android app development with Xamarin:

1. Debug Mode: Fast Deployment

In the Debug Mode of Xamarin, you can find fast deployment features that can save deployment time by placing DLLs (assemblies) into the app data directory. Hence, no time is wasted developing the APKs each time & reinstalling it. 

Here is how you can enable the option using Visual Studio IDE, 2019, 16.3.1 on Windows.

Visual Studio IDE

 To open settings: Go to Project -> Properties

Properties


By enabling the option to use fast deployment, you can speed up the debug turnaround cycle as it skips APK creation, uninstallation & installation.   

2. Debug Mode: Multi-Dex

Android APK files include executable bytecode files as Dex files (Dalvik Executable files) that hold the compiled code used to execute your Android app. Android Build Architecture has limited the use of this reference to the app & the libraries to 65, 536 methods. If you want to skip this limitation, you can enable the configuration, Enable Multi-Dex.

However, this incremental build using Multi-Dex generally takes a long time and slows down your development process. As such, if your Xamarin android app is under the Dex limit, uncheck the Enable multi-dex option. (P.S. If you get an error while building the project, then you need to check the option.) 

Debug Mode: Multi-Dex


3. Release Builds: Configuration

At the release stage of the application, you can use these options to make your application as small as possible. The two main goals it accomplishes are Faster Start-up time and Smallest APK size. 

Release Builds: Configuration


Garbage Collector:
It is meant to release memory space. Enabling “use the concurrent garbage collector” allows you to perform the Garbage Collection concurrently while your app program is running. This avoids the large pauses when your application has large memory piles to be collected. 

Linking: This helps to make your APK file size smaller. When your application is in the release stage, select the SDK and user assemblies under the linking option. It performs static analysis and tracks which assemblies, members and types are used and links them with your project.

Shrinker: Similarly, your application should empower a Java Code Shrinker, like ProGuard. ProGuard is an optimizer. It detects and removes unused fields, classes, attributes, and methods. ProGuard principles enable engineers to be certain about which Java classes must be kept through linking.

Other Best Practices to reduce Andriod App Size

  • Use Android App Bundles to upload on google play store - Recommended publishing format of the Android app on Google play store. It enables you to reduce your app size, streamline releases as well as deliver features on demand.
  • Decrease resource count and size - Eliminate all the unused resources from the app.
  • Minimize resource use from libraries - While developing xamarin.droid apps we do use external libraries. Make sure to use only the mobile data part before using the library, since many libraries contain the server or desktop design data, which doesn’t require mobile apps.
  • Support only specific densities - Android supports an extremely huge set of gadgets, enveloping an assortment of screen pixel densities. In Android OS version 4.4 and above, the system underpins different densities like ldpi, mdpi, tvdpi, hdpi, xhdpi, xxhdpi and xxxhdpi.

If your application needs just scaled pictures, you can spare much more space by having a solitary variation of a picture in drawable-nodpi folder.                                                                                                                           

  • Use drawable objects - Use a dynamic image source where a static image is not required in the app.
  • Render from code (use vector) - Procedural rendering opens up space since you never again store a picture record in your APK.
  • Crunch all PNG files & Compress PNG and JPEG images - You can shrink the images of your apps and sites using TinyPNG. It will use less bandwidth and load faster.
  • Use WebP file format for the images - An alternate to image formats like PNG or JPEG. It results images in smaller file sizes, but with similar image quality.

Xamarin is offering these simple but powerful ways to reduce the size of your mobile application. Hence, enterprises are now opting to perform their mobile development with Xamarin. This not only reduces the size but also lets their product enter into the application market quickly.

Author

Table of Contents

Talk To Our Experts