Since the Android Marketplace launched in March 2012, boilerplate app admeasurement has quintupled. Some of this admission makes sense. Today, we apprehend richer content, bigger graphics, and added appearance from our adaptable apps, and none of this comes for free! The anamnesis attainable on your archetypal Android accessory has increased, so why shouldn’t apps accomplish use of this added amplitude if it helps them bear a bigger user experience?
If your app is activity to ability as abounding users as possible, you charge to pay absorption to the admeasurement of your Android Package Kit (APK). A recent study published by a Action and Operations Analyst at Google showed APK admeasurement anon affects the cardinal of bodies who end up installing your appliance afterwards visiting its abundance page. According to these findings, for every 6 MB admission in the admeasurement of your APK, you can apprehend to see a 1 percent abatement in the accession about-face rate.
There are abounding affidavit why the admeasurement of your APK ability be captivation your appliance back:
In this article, I’m activity to appearance you how to ensure bodies visiting your app’s Google Play folio absolutely end up installing it by administration tools, techniques, and new appearance to advice actualize a abundant bacteria APK.
ProGuard is a apparatus which can analyze and abolish bare classes, fields, methods, and attributes from your appliance cipher and any libraries you may be using.
For the best aftereffect use the proguard-android-optimize.txt file, which has the aforementioned settings as the absence proguard-android.txt file, but with optimizations that accomplish assay central and beyond methods.
Here’s how to accredit ProGuard in your project’s module-level build.gradle file:
Every time you body your project, ProGuard will accomplish a app/build/outputs/mapping/release/usage.txt book that lists aggregate ProGuard has removed from your APK, so analysis it to accomplish abiding it hasn’t bare abroad any cipher your activity absolutely needs.
If ProGuard does abolish all-important code, again attainable the build/intermediates/proguard-files/proguard-android-optimize.txt-3.0.1.txt book and use the -keep banderole to specify the cipher that you appetite to adhere onto:
Since ProGuard may abolish cipher that your activity does absolutely require, you should consistently analysis your activity with ProGuard enabled, afore publishing your final APK.
Sometimes bare assets can acquisition their way into your project, decidedly if you’re appliance libraries. Since unreferenced assets are aloof demography up accidental space, you should acquaint Gradle to chase for, and abolish these assets by enabling ability shrinking:
See Also: hack imoWhenever you body your project, the Gradle Console will accommodate an overview of how abounding assets it’s managed to remove, but you can appearance a account of these assets in your project’s app/build/outputs/mapping/release/resources.txt file.
While ability shrinking can advice abate the admeasurement of your APK, it has its limitations. It cannot abolish assets from the “values” folder, and it won’t abolish accidental another resources.
You should use ability shrinking in aggregate with Lint, a changeless scanning apparatus which can analyze assets that aren’t referenced in your code.s
To run Lint, baddest Analyze — Inspect Code… from the Android Studio toolbar. If Lint detects any bare resources, again it’ll affectation the afterward bulletin in a new Inspection Results window: “Unused resources — The ability R.drawable.ic_launcher_background2 appears to be unused.”
Lint can alone ascertain bare resources, so you’ll still charge to abolish them manually.
Graphical assets are generally the bigger contributor to APK size, so burden your drawables can decidedly abate the size. If you’re alive with JPEGs, you can try a compression apparatus such as packJPG. If your activity contains PNGs you can use zopflipng, pngcrush, OptiPNG, TinyPNG or pngquant.
The Android Asset Packaging Apparatus (AAPT) optimizes the capacity of your res/drawable folder automatically. If you abbreviate your PNGs afore casual them to AAPT, again it may absolutely end up inflating your PNGs.
If you abbreviate your PNGs manually, accomplish abiding you attenuate the AAPT action for them like this:
If your project’s minSdkVersion is 18 or higher, converting a PNG, JPEG or BMP to WebP architecture generally provides bigger compression, as able-bodied as the aforementioned angel quality.
If you about-face to WebP, you’ll still charge to accommodate your launcher figure as a PNG.
If you charge to use variations of the aforementioned image, try to accumulation a distinct “base” angel that you adapt at runtime wherever possible. You can administer a cast to an angel appliance setTint() and circle drawables appliance attributes like android:fromDegrees and android:pivotY.
On Android 5.0 and higher, you can draw assets at runtime by defining a VectorDrawable, which is an XML representation of a vector. These XML files accommodate aisle commands cogent Android how to draw the curve and arcs that accomplish up this graphic.
Unlike abounding angel formats, vectors can calibration after accident definition, so you alone charge to accommodate one asset per image. However, apprehension VectorDrawable altar is an accelerated process, and you should alone use them for small, simple graphics.
Before abacus any library to your project, you should analysis its cipher admeasurement so you apperceive absolutely what appulse it’s activity to accept on your final APK. You should additionally attending alarmingly at the appearance this library provides, as it may accommodate a cogent aggregate of code, as able-bodied as assets your activity doesn’t absolutely need. For best results, consistently accept a library that’s compact, optimized for mobile, and contains alone the appearance that you’re absolutely activity to use.
There’s no curtailment of third-party libraries out there, so it’s consistently account arcade about to acquisition the aboriginal library that still meets your needs.
Libraries may accommodate strings for a ambit of languages, but if you activity doesn’t absolutely abutment these languages again these strings are aloof abacus accidental aggregate to your final APK.
Open your build.gradle book and specify the languages that your appliance clearly supports, again Gradle will automatically exclude all assets for languages your appliance doesn’t support, including strings from third affair libraries:
Many projects use Google Play Services. Rather than abacus the absolute library to your project, you should alone accommodate the APIs you’re absolutely activity to use. If you alone crave admission to the Google Area APIs, again aloof use this:
Rather than this:
It’s appealing accepted convenance to broadcast a distinct APK absolute alternating assets for altered accessory configurations. Occasionally this action may crave users to download a ample cardinal of assets they’ll never use. If your APK is arranged with high-density graphics, you’re about allurement users on low-density screens to decay adored accumulator amplitude on images their accessory physically cannot display.
In this scenario, you may appetite to accede amid your distinct APK into assorted APKs which accommodate alone the cipher and assets appropriate for specific awning densities or Appliance Binary Interfaces (ABIs). Back the user downloads your app from Google Play, they’ll accept an APK absolute aloof the assets to ambition their accurate device.
To accomplish APKs based on awning density, add the afterward to your build.gradle file:
Even if you accomplish assorted APKs for specific awning densities, Gradle will consistently accomplish an APK absolute the assets for all awning densities, so accomplish abiding you broadcast this accepted APK to accommodate a fallback for accessories that don’t bout any of your density-specific APKs.
Different Android accessories use altered CPUs, which in about-face abutment altered apprenticeship sets. Anniversary aggregate of CPU and apprenticeship set has an ABI, which defines how the application’s apparatus cipher interacts with the system.
Gradle bundles the binaries for all ABIs into a distinct APK by default, but you can additionally actualize APKs based on ABI. Back you acquaint Gradle to accomplish ABI-specific APKs, it won’t automatically accomplish a accepted APK, so you’ll charge to accommodate absolute instructions to actualize this accepted APK:
Google Play will not acquiesce you to upload assorted APKs to the aforementioned listing, if those APKs accept the aforementioned adaptation information. If you actualize assorted APKs, you’ll charge to accredit anniversary APK its own versionCode value.
Some users may accept to extend their device’s congenital anamnesis by abacus alien accumulator (most frequently an SD card). Unless you appeal otherwise, Android will anticipate the arrangement from installing your app on alien storage, so accession will abort if there isn’t able on-device storage, admitting affluence of alien accumulator is available.
To accord Android the advantage of installing your app on alien storage, attainable your project’s Manifest, and add either of the afterward lines:
Even if your APK is installed on alien storage, all clandestine user data, databases, optimized .dex files, and extracted built-in cipher will still be adored to centralized memory.
If you chase all the aloft techniques and best practices, you should be able to decidedly abate the admeasurement of your APK. No amount how abbreviate your APK, the action of downloading and installing an app will always be the bigger barrier amid your appliance and abeyant new users.
So why not accord users a way to acquaintance your appliance without installing your APK?
Android’s “Instant Apps” affection lets you abstracted your app’s best important functionality into stand-alone modules, and map anniversary of these modules to a URL. The user can again amount a bore on appeal by beat its URL, which makes your app instantly attainable from any area that supports URLs, like emails, Google chase results, forums, and YouTube comments.
Behind the scenes, Burning Apps are delivered via a failing Burning Apps APK which contains alone the cipher and assets appropriate to bear this accurate feature, and always comes in at 4MB or under.
For users disturbing with accumulator space, connectivity issues, or akin abstracts plans, burning apps may be the alone applicable way of experiencing what your appliance has to offer. Hopefully, their acquaintance with your Burning App will actuate them to install the complete APK added bottomward the line, already they’re able.
To ensure users aren’t put off by the admeasurement of your app or aren’t able to install it because it takes up too abundant of the centralized storage, it is important to abate the admeasurement of your final APK file. The techniques aloft could accompany some affecting accumulation which hopefully will catechumen anon into downloads and a convalescent installed base.
- The user notices the APK admeasurement on your app’s Google Play listing, and decides not to install it based on this information.
- The user is abutting their abstracts absolute and doesn’t appetite to acquire added costs.
- The accession fails due to a abridgement of amplitude on the ambition device. This is a problem particularly in markets area account accessories are added common, such as arising markets.
- The accession fails due to arrangement connectivity issues, which are added acceptable to action during diffuse downloads.
- In Android Studio, control-click the angel you appetite to convert, or a binder absolute assorted images.
- Select Convert to WebP…
- In the abutting menu, accept amid lossy or lossless encoding.
- Check the Skip images back the encoded aftereffect is beyond than the original box.
- Click OK to accomplish the conversion.
- android:installLocation=”preferExternal.” Your app prefers to be stored externally, but can additionally be installed on centralized storage.
- android:installLocation=”auto.” Your app can be installed on centralized or alien storage, but the arrangement will install your app on centralized accumulator by default.
Remove bare methods and classes with ProGuard
Remove all unreferenced resources
Compress your drawables
Switch to WebP
Modify images at runtime
Use agent graphics
Always do your research
Remove bare library code
Get specific with Google Play Services
Consider creating assorted APKs
Allow your app to be installed on alien storage
Consider alms your activity as an Burning App
Wrapping up
buildTypes { absolution { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } }
-keep attainable chic MyActivity
buildTypes { absolution { shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
android { aaptOptions { cruncherEnabled = false }
android { defaultConfig { //Use resConfigs to specify the languages that your app clearly supports// resConfigs "en"
implementation 'com.google.android.gms:play-services-location:11.8.0'
implementation 'com.google.android.gms:play-services:11.8.0'
android { ... ... ... //Create a ‘splits’ block// splits { //Create a ‘density’ block// body { accredit true //Generate abstracted APKs for the afterward awning densities// include "ldpi", "mdpi"
android { ... //Create a ‘splits’ block// splits { //Create an ‘ABI’ block// abi { //Build assorted APKs based on ABI// accredit true //Generate abstracted APKs for the afterward ABIs// accommodate "arm64-v8a", "armeabi-v7a", "x86" //Generate a accepted APK// universalApk true } } }
For every 6MB admission in the admeasurement of your APK, you can apprehend to see a 1% abatement in the accession about-face rate.
On Android 5.0 and higher, you can draw assets at runtime by defining a VectorDrawable, which is an XML representation of a vector.
For users who are disturbing with accumulator space, connectivity issues or akin abstracts plans, burning apps may be the alone applicable way of experiencing what your appliance has to offer.
Comments
Post a Comment