8 Ways to Reduce Your Android App APK Size

Since the Marketplace launched in March 2012, the dimensions of the common app has quintupled.Eight Ways to Reduce Your Android App APK Size

Some of this enhance is smart: the reminiscence accessible to the everyday Android system has elevated, so why not use this further reminiscence to ship a greater person expertise?

However, there is some extent the place all of these high-definition graphics, modern options and wealthy, multimedia content material have a unfavorable impression on the person expertise—no-one desires an app that takes eternally to obtain after which takes a bit out of their system’s reminiscence!

There’s even proof to counsel that there’s an inverse correlation between the dimensions of your and the quantity of people that obtain your app. According to a recent study, for each 6MB enhance in dimension, you’ll be able to anticipate a 1% drop within the quantity of people that set up your app after visiting its Google Play web page.

Everything you are able to do to cut back the dimensions of your APK will encourage extra customers to obtain your app, so on this article I’ll present you how one can create a trimmer, slimmer APK and guarantee your app winds up on as many gadgets as doable.

Android Bundles: Support More Devices, While Reducing APK

Whenever you develop an Android app, you’ll need to be sure that app is suitable with as many various gadgets as doable, by offering code and sources which might be optimized for various display densities, CPU architectures, languages, and plenty of different elements. Unfortunately, this additionally signifies that each single one that downloads your app will obtain a ton of code and sources that they’re by no means going to make use of.

Supporting as many gadgets as doable with out dramatically growing the dimensions of your APK has lengthy been an issue for Android builders. However, the Android group are aiming to vary all this, with a brand new publishing format that’s designed that can assist you help the complete vary of Android gadgets, whereas lowering the dimensions of your APK. According to the official Android Developers blog, by publishing your app on this new Android App Bundle (.aab) format, you need to have the ability to cut back the dimensions of your APK by a mean of 35%.

Once you’ve uploaded your app as an .aab file, Google Play will use this single file to generate:

  • A base APK containing all of the code and sources required to ship your app’s base performance. Everyone who downloads your app will obtain the identical base APK.
  • Multiple configuration APKs, that are tailor-made to completely different system configurations. Every time somebody downloads your app, they’ll obtain a configuration APK that’s tailor-made to their particular system and comprises solely the code and sources they really want.

To construct your app as a signed Android App Bundle, first choose Build > Generate Signed Bundle/APK from the Android Studio toolbar. Then choose the Android App Bundle checkbox, after which click on Next. Now, open the module dropdown, and select app as your base module.

Follow the onscreen directions to finish the construct course of. Android Studio will now generate an .aab file and retailer it in your laptop’s AndroidAppBundle/app/launch listing.

When you’re able to add your .aab file to Google Play, simply head over to the Google Play Console and choose Create Application.

You’ll be requested to enter some primary details about your app after which click on Create, adopted by Save. In the Console’s left-hand menu, choose App releases. Decide which monitor you need to add this app to, after which choose its accompanying Manage button and click on Create launch.

When prompted, enroll in App Signing by Google Play, which is necessary for utilizing the App Bundle format. Select Browse recordsdata after which choose the .aab file that you just need to add.

Upload your Android App Bundle to the Google Play Console

Finally, click on Save to avoid wasting your configuration.

Once you’ve uploaded your app to the Console, you’ll be able to see how a lot space you’ve saved by utilizing the App Bundle format. To accomplish that, choose App releases from the left-hand menu. Find the monitor the place you uploaded your Bundle, after which choose Edit launch then click on to increase the Android App Bundle part.

Select Explore App Bundle, and also you’ll see a tough estimate of the space you’ve saved, expressed as a proportion.

Check how much space youve saved your users by using the aab format

Deliver Features on Demand, With Dynamic Feature Modules

It’s common for a undertaking to have a number of options that aren’t essential to ship that software’s core performance. You can usually cut back the dimensions of your APK by separating these options into optionally available dynamic characteristic APKs, which the person can then obtain on demand, as and when required.

To create a dynamic characteristic module, choose File > New > New Module… from the Android Studio toolbar. Select Dynamic Feature Module, adopted by Next.

From right here, you’ll be able to open the Base software module dropdown and choose your base module. Give your module a reputation, after which click on Next. Select the Enable on-demand checkbox. If your undertaking helps Android 4.Four or earlier, you then’ll additionally have to allow Fusing, as this may make your dynamic characteristic module accessible to those gadgets as a multi-APK.

Select the Enable on-demand and Fusing checkboxes

Finally, give your module a public identify, which will likely be seen to the tip person. Click Finish.

Enabling Access to the Dynamic Feature Module

Once you’ve created a dynamic characteristic module, you’ll want to present customers a option to request it at runtime. Open your module-level construct.gradle file, and add the Google Play Core library as a undertaking dependency:

Open the Activity or Fragment the place you need to load your dynamic characteristic module, after which add the next:

You can now add code and sources to your dynamic characteristic module, and customers will have the ability to request the module at runtime.

Try Before You Buy: Offer an Instant Apps APK

It might not be an APK within the conventional, installable sense, however you’ll be able to supply a part of your software as a light-weight, standalone Instant Apps APK that customers can then load on demand. For anybody who’s battling extraordinarily restricted storage or a restrictive knowledge plan, Instant Apps often is the solely viable means for them to expertise your software.

In our three-part Instant Apps series, we created a multi-feature Instant Apps APK that was mapped to a novel URL. URL mapping makes your Instant App accessible from any location on the net that helps hyperlinks, together with boards, tweets, Facebook posts, and blogs. However, URL mapping can be a multi-step course of that requires you to personal an internet area the place you’ll be able to host your undertaking’s assetlinks.json file.

In the most recent variations of Android Studio, creating an Instant Apps APK simply bought simpler, because it’s now doable to create an Instant App that isn’t mapped to any URL, eradicating the entire complexity related to URL mapping.

Once you’ve revealed your URL-less Instant App, customers will have the ability to entry it by way of a Try Now button in your app’s Google Play itemizing.

The BuzzFeed app is one example of an Android Instant App

To create these sort of “URL-less” Instant Apps, you’ll want:

  • Android Studio 3.2 or increased.
  • Instant Apps Development SDK 1.3.zero or increased.
  • The newest variations of the Android SDK Build and Platform instruments.

Projects that help Instant Apps have a novel construction. If you observe modularization as a part of your normal app improvement course of, then it’s possible you’ll solely have to make some tweaks to your undertaking, but when your undertaking isn’t modularized, then be ready to spend a while restructuring it.

To help Instant Apps, you’ll have to create the next modules:

  • App module. This is the “standard” installable app module.
  • Base module. This comprises the code and sources that’ll be used throughout all your undertaking’s modules, comparable to your app’s launcher icons.
  • Feature module. This comprises the code and sources which might be required to ship a stand-alone characteristic.
  • Instantapp module. This is a container that’ll ultimately take every of your undertaking’s characteristic modules, and remodel them into Instant App APKs.
The structure of an Instant App-enabled project

For a extra detailed take a look at this distinctive undertaking construction, try: What Are Android Instant Apps?

  • Android SDK

    What Are Android Instant Apps?

    Jessica Thornsby

     

If you’re beginning a brand new undertaking, you then’re in luck: you’ll be able to create a clean undertaking that already has the Instant Apps construction. Simply create a brand new undertaking as regular, however when prompted, choose This undertaking will help instantaneous apps.

When creating a project make sure you select the following checkbox This project will support instant apps

You can then add code and sources to every module, as regular.

To check your URL-less Instant App, you’ll want a suitable system, which in keeping with the official Android docs is “most” bodily gadgets operating Android 5.1 or increased. If you’re utilizing the emulator, you then’ll want an AVD (Android Virtual Device) that’s utilizing Android 8.1 or later, x86 structure, and consists of the Google APIs. You’ll additionally should be logged in to a legitimate Google account in your check system or AVD.

To put your Instant App to the check, choose Run > Run… from the Android Studio toolbar and then choose Edit Configurations

In the left-hand menu, choose instantapp. Since we’re testing a URL-less Instant App, discover the URL subject and delete the entire textual content inside it. Now choose Run. If the system prompts you to choose into the Instant App program, then faucet Yes, I’m in.

Your Instant App ought to now seem onscreen, with no set up and no URL required!

When it’s time to launch your app, you’ll be able to both full the signing course of twice with the intention to create separate installable and Instant App APKs or you’ll be able to construct your undertaking as an App Bundle.

Publish an Instant Apps-Enabled App Bundle

In the Android Studio 3.Three beta 1 and better, you’ll be able to mix Instant Apps with App Bundles, to create a single .aab file that options each your installable and Instant App.

To set your app as much as publish an .aab file with an Instant App included, open your undertaking’s instantapp module.

In this module’s AndroidManifest.xml file, add the next:

Open your app module’s construct.gradle file, and guarantee your instantaneous variant has a smaller modelCode than its installable counterpart:

Select Build > Generate Signed Bundle / APK from the Android Studio menu bar, after which construct your App Bundle as regular, ensuring to signal it with a launch key.

Remove All Unused Methods, Classes, Fields, Attributes, and Resources

It’s straightforward for unused code and sources to search out their means into your undertaking, significantly once you’re utilizing libraries. Since they add zero worth to your app, you need to all the time monitor down and take away pointless belongings, and there are a number of instruments that may assist you to:

1. Feeling Adventurous? Try the New R8 Code Shrinker

Code shrinking might help you cut back the dimensions of your APK by deleting unused code and sources.

Android Studio 3.Three beta 1 encompasses a preview of the upcoming R8 code shrinking device, which additionally performs desugaring and dexing and, in keeping with Google, shrinks code sooner than ProGuard.

To strive R8 for your self, be sure to’re operating Android Studio 3.Three beta 1 or increased, after which add the next to your gradle.properties file:

2. Shrink Your Code With ProGuard

At the time of writing, R8 was nonetheless in preview, so till it’s steady you would possibly want to make use of ProGuard to take away unused lessons, strategies, fields and attributes out of your code.

To allow ProGuard, add the next to your module-level construct.gradle file:

Just bear in mind that ProGuard could take away code that your software truly wants, so you need to all the time check your undertaking with ProGuard enabled, earlier than publishing it.

3. Enable Resource Shrinking

Once you’ve enabled code shrinking, you should utilize useful resource shrinking to identification and take away pointless sources:

4. Improve Your Code With Android Lint

Lint is a static scanning device that may establish sources that aren’t referenced wherever in your code. However, Lint doesn’t truly take away these sources, so that you’ll have to examine its report and take away the recognized sources manually.

To run Lint, choose Analyze > Inspect Code… from the Android Studio toolbar. If Lint detects any unreferenced sources, then it’ll checklist them in its Inspection Results window.

After running a Lint inspection you can check its findings in the Inspection Results window

Convert Your PNGs, JPEGs and BMPs Into WebP

If your undertaking comprises a variety of drawables, then compressing them can considerably cut back the dimensions of your APK.

If your undertaking’s minSdkVersion is 18 or increased, then you’ll be able to compress your PNGs, JPEGs and BMPs by changing them to WebP format.

First, control-click the drawable that you just need to convert and choose Convert to WebP… Choose between lossy, or lossless encoding. Select Skip pictures when the encoded result’s bigger than the unique and click on OK to transform the picture.

Examine Your APK Using Android Studio’s APK Analyzer

Sometimes, you might not be totally certain what’s precipitated your APK to develop uncontrolled.

You can establish the largest contributors in the direction of the dimensions of your APK by utilizing Android Studio’s new APK Analyzer. This device helps you to discover absolutely the and relative dimension of various classes of recordsdata, and even the dimensions of particular person recordsdata, so that you’ll know precisely the place try to be focusing your efforts.

To analyze an APK, simply choose Build > Analyze APK from Android Studio’s menu bar.

In the following window, choose the APK in query. The APK Analyzer will open in a brand new panel.

The APK Analyzer displays the raw and download size of every file that makes up your APK

For every file and folder, the APK Analyzer shows:

  • Raw file dimension. This is the unzipped dimension of this merchandise on the disk.
  • Download dimension. This is the estimated compressed dimension of the merchandise, as it could be delivered by Google Play.
  • % of whole obtain dimension. The proportion of the APK’s whole obtain dimension that this merchandise represents.

This isn’t the one characteristic the APK Analyzer has to supply.

Imagine you’ve efficiently slashed the dimensions of your APK and launched a light-weight software that amasses glowing five-star evaluations on Google Play—that doesn’t imply you’ll be able to cease worrying about APK dimension! At some level, you’ll need to launch an replace, which implies APK dimension will as soon as once more turn into a serious concern.

While it’s all the time a good suggestion to watch how your APK evolves from one launch to the subsequent, if there’s ever a serious enhance in APK dimension you then’ll positively need to take a better take a look at what’s happening.

You can use the APK Analyzer to spotlight all of the variations between your present APK and your earlier APK, which might help you zero in on areas and belongings that you might optimize and even take away fully.

To examine APKs, first choose Build > Analyze APK from Android Studio’s menu bar.

Then choose the newest model of your APK. In the upper-right nook of the APK Analyzer, choose Compare with earlier APK… Next, choose the earlier model of your APK. A popup ought to seem, highlighting all of the variations between your present APK and your earlier APK.

Don’t Forget Android Go!

Emerging markets signify a number of the quickest rising smartphone audiences on the earth, and the rise of manufacturers like Vivo and Oppo has confirmed that finances gadgets have the potential to dominate this rapidly-expanding market.

To assist Android attraction to this totally new and rising viewers, Google have launched Android Go, a model of Android with efficiency and storage enhancements designed to offer a greater expertise on budget-friendly gadgets, together with gadgets which have lower than 1GB of RAM.

Android Go customers have entry to all the Google Play retailer, however Google highlights apps which might be optimized for Android Go, together with purposes that take up lower than 40MB on the person’s system.

By following the recommendation on this article, you need to have the ability to considerably cut back the dimensions of your APK for everybody who makes use of it. However, if you wish to make some further reductions particularly for Android Go customers, then you should utilize Android’s multi-APK feature to publish an APK that’s optimized for the Android Go platform.

To create a devoted Android Go app, you’ll have to create an APK that has the identical bundle identify and signing certificates as your “regular” app, however has a novel model code.

When creating your Android Go APK, you’ll additionally want so as to add the next to your Manifest:

You might also like More from author

Leave A Reply

Your email address will not be published.