Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

4.2 How to Reducing APK size by using ABI Filters and APK split.

ads

 How to Reducing APK size by using ABI Filters and APK split.

ads

This text describes methods of managing native libraries in Android packages.

ads

these days native libraries emerge as increasingly more popular. they are particularly created for overall performance, safety and pass-platform portability reasons. famous examples are cohesion, Realm, and OnFido.

ads

rather than Android packages that run on Android digital system (Dalvik or Android Runtime(artwork)), local libraries are compiled directly into native processor (CPU) code. This code varies depending on architecture (set of commands) supported via the processor. The Android platform supports more than one processor architectures:

ads

mips

mips64

armeabi

armeabi-v7a

arm64-v8a

x86

x86_64

If we need to use native libraries in our software, we ought to provide exclusive compilations for each of the CPU architectures we want to assist. For every architecture we have one or extra separate .so documents containing local code:


ads

local libraries in the project

when we decide to assist CPU architectures, our APK (application package) report size can develop like crazy. whilst a consumer downloads the app, despite handiest desiring the set for his device structure, he’ll get they all.

ads

allow’s use APK Analyzer (that is provided with Android Studio 3) and check what happens internal our APK containing local libraries:


ads

After jogging examine APK command and selecting APK report we can test its internals. we are able to immediately observe that lib folder that consists of local libraries is the largest folder in the APK report:

ads


lib folder 45MB

whilst we take a more in-depth look we see how much area is consumed by way of local libraries for every structure:


ads

cutting-edge APK restriction in Google Play store is 100MB. Our local libraries devour 45MB which is nearly 1/2 of allowed APK space. To decrease APK size we want to limit our APK to guide sure architecture(s). There are  techniques that we must keep in mind:

ads

ABI Filters

APK split

ABI filters

ABI (software Binary Interface) is an interface between  software modules; frequently, this type of modules is a library or working system facility

ads

ABI filters allow us to filter out positive form of architecture(s) that we need to include into single APK document.


ads

by way of putting off useless architectures we can generate single APK report that has much smaller size (notice that there are not many gadgets that help x86 structure for Android, however the libraries for this architecture are the largest ones).


ads

we are able to apply ABI filters to default config to have an effect on all the builds. The downside is if we need to check our builds on emulator we commonly want local libraries for x86/x86_64 architecture. That’s why it can be the better concept to configure filters only for our release construct.

ads

This solution has pros and cons, so let’s remember  points of view — consumer perspective and developer perspective.

ads

From the consumer attitude, APK carries more libraries than person wishes ( architectures instead of one), so this means bigger APK length. at the end, the person will use extra cell community records and wait longer for application to download set up. this could decrease general UX.

ads

understand that in some emerging markets (like India) cellular records switch is pretty costly. customers frequently proportion the utility the usage of Bluetooth or hot-Spot thru SHAREit or Xender (those apps have around a hundred-150M users). If we downloaded app that carries local libraries best for arm64-v8a architecture it's going to now not also be running whilst we percentage with the tool helping armeabi-v7a after sharing the APK record (other ways round this will paintings because arm-v8a is backward well matched).

ads

From a developer angle, this solution gives unmarried APK to preserve that can keep us loads of time. this indicates no extra overhead associated with configuring construct technique and APK checking out and upkeep (study right here about supporting multiple APKs).

ads

If we use a single library that adds most effective few MBs for every architecture then ordinary “person price” can be small and a couple of APKs may not be worth the our attempt. but whilst we use a couple of local libraries total size of the libraries for every platform may be pretty big:


ads

85–42MB, armebai-v7a-31MB, arm64-v8a sixteen.2MB

If we care about users transfer or exceed 100MB APK limit ABI filters are not an option. We want to make sure that customers will download only the native libraries that they really need. That’s where APK break up comes into play.

ads

APK break up

Apk break up permits us to generate more than one APK files. we can carry out split by way of display density (mdpi, hdpi, xhdpi…) or architecture (arm64-v8a, armeabi-v7a…). permit’s configure cut up by using architecture:

ads


One APK report per each architecture will be generated and (optionally) one frequent document containing all architectures.


ads

If we might also configure splits by display density then APK documents for all density+structure mixtures could be generated (app-united kingdom-mdpiArmeabi-v7a-debug.apk, app-united kingdom-mdpiArm64-v8a-debug.apk, app-uk-hdpiArmeabi-v7a-debug.apk, app-united kingdom-hdpiArm64-v8a-debug.apk, and many others.).

ads

For debugging reason cut up can be needless, so we can configure splits most effective for our release builds. There are few approaches to approach this. we can bypass a parameter for Gradle build script to explicitly say that this construct must be cut up. in case you need to have capacity to allow or disable splitting for your construct server this is a manner to go. but we also can configure splits for release build through retrieving Gradle venture call while project is going for walks. this can permits us to decide if the present day Gradle challenge is a undertaking that creates launch build (eg. assamblePaidRelease) and make decision whatever we need to allow APK cut up or no longer:


ads

Now jogging assembleRelease duties for each flavour will generate more than one APK documents splited by means of CPU structure, even as walking assembleDebug tasks will generate unmarried APK file.

ads

version codes

Google Play keep does now not permit to add multiple APK documents with the identical version code. We need to ensure every APK has its personal specific versionCode.


ads

This code will permits us to override model code for every APK



to check if model code changed into properly generated we are able to open generated APK document using APK Analyzer and pick AndroidManifest.xml record to display it’s content material.

ads


We may also replace version call (eg. 3.13.0.seventy eight-arm64-v8a) to reflect modern architecture by editing extra versionNameOverride property inside the preceding code. We want to do it simplest while abiName isn't always null (we need to depart the name of ordinary APK intact)

ads

Which architectures to aid

We virtually need to help armeabi-v7a and arm64-v8a architectures because they have got around ninety nine% of marketplace propagation. With x86/x86_64 there may be an exciting case. From the cell market angle, they're insignificant and that is not likely to change within the destiny. however, Google is pushing builders to make their Android apps well suited with Chromebooks which might be ordinarily using Intel processors based on x86/x86_64 structure (meaning we can don't forget adding assist for it).

ads

most of the Chromebooks have Intel processors supporting Intel® VT-x, letting them run HAXM (the equal era we use to make apps in our emulators run a good deal quicker), so the app emulation is pretty rapid.

ads

Summing up here is a entire listing of Android architectures with usage recommendations:

ads

mips (deprecated)

mips64 (deprecated)

armeabi (deprecated)

armeabi-v7a (required — most popular structure in recent times)

arm64-v8a (required — more recent version of armeabi-v7a)

ads

x86 (optionally available, very constrained wide variety of gadgets, may be beneficial for debugging within the emulator)

ads

x86_64 (non-obligatory, very limited number of gadgets, can be beneficial for debugging in the emulator)

conclusion

ads

As we are able to see there are no golden rules here. the answer that we may also need relies upon on our native libraries length, potential to properly configure and control construct/launch manner and marketplace we want to goal.


ads

earlier than you make a decision approximately the usage of ABI filters or APK break up we ought to examine the scale of our local libraries, check our consumer base and decide how many customers will absolutely benefit from this modification. additionally we need to don't forget price of average overhead on our side.

ads

This text describes methods of managing native libraries in Android packages.

ads

these days native libraries emerge as increasingly more popular. they are particularly created for overall performance, safety and pass-platform portability reasons. famous examples are cohesion, Realm, and OnFido.

ads

rather than Android packages that run on Android digital system (Dalvik or Android Runtime(artwork)), local libraries are compiled directly into native processor (CPU) code. This code varies depending on architecture (set of commands) supported via the processor. The Android platform supports more than one processor architectures:

ads

mips

mips64

armeabi

armeabi-v7a

arm64-v8a

x86

x86_64

If we need to use native libraries in our software, we ought to provide exclusive compilations for each of the CPU architectures we want to assist. For every architecture we have one or extra separate .so documents containing local code:


ads

local libraries in the project

when we decide to assist CPU architectures, our APK (application package) report size can develop like crazy. whilst a consumer downloads the app, despite handiest desiring the set for his device structure, he’ll get they all.

ads

allow’s use APK Analyzer (that is provided with Android Studio 3) and check what happens internal our APK containing local libraries:


ads

After jogging examine APK command and selecting APK report we can test its internals. we are able to immediately observe that lib folder that consists of local libraries is the largest folder in the APK report:

ads


lib folder 45MB

whilst we take a more in-depth look we see how much area is consumed by way of local libraries for every structure:


ads

cutting-edge APK restriction in Google Play store is 100MB. Our local libraries devour 45MB which is nearly 1/2 of allowed APK space. To decrease APK size we want to limit our APK to guide sure architecture(s). There are  techniques that we must keep in mind:

ads

ABI Filters

APK split

ABI filters

ABI (software Binary Interface) is an interface between  software modules; frequently, this type of modules is a library or working system facility

ads

ABI filters allow us to filter out positive form of architecture(s) that we need to include into single APK document.


ads

by way of putting off useless architectures we can generate single APK report that has much smaller size (notice that there are not many gadgets that help x86 structure for Android, however the libraries for this architecture are the largest ones).


ads

we are able to apply ABI filters to default config to have an effect on all the builds. The downside is if we need to check our builds on emulator we commonly want local libraries for x86/x86_64 architecture. That’s why it can be the better concept to configure filters only for our release construct.

ads

This solution has pros and cons, so let’s remember  points of view — consumer perspective and developer perspective.

ads

From the consumer attitude, APK carries more libraries than person wishes ( architectures instead of one), so this means bigger APK length. at the end, the person will use extra cell community records and wait longer for application to download set up. this could decrease general UX.

ads

understand that in some emerging markets (like India) cellular records switch is pretty costly. customers frequently proportion the utility the usage of Bluetooth or hot-Spot thru SHAREit or Xender (those apps have around a hundred-150M users). If we downloaded app that carries local libraries best for arm64-v8a architecture it's going to now not also be running whilst we percentage with the tool helping armeabi-v7a after sharing the APK record (other ways round this will paintings because arm-v8a is backward well matched).

ads

From a developer angle, this solution gives unmarried APK to preserve that can keep us loads of time. this indicates no extra overhead associated with configuring construct technique and APK checking out and upkeep (study right here about supporting multiple APKs).

ads

If we use a single library that adds most effective few MBs for every architecture then ordinary “person price” can be small and a couple of APKs may not be worth the our attempt. but whilst we use a couple of local libraries total size of the libraries for every platform may be pretty big:


ads

85–42MB, armebai-v7a-31MB, arm64-v8a sixteen.2MB

If we care about users transfer or exceed 100MB APK limit ABI filters are not an option. We want to make sure that customers will download only the native libraries that they really need. That’s where APK break up comes into play.

ads

APK break up

Apk break up permits us to generate more than one APK files. we can carry out split by way of display density (mdpi, hdpi, xhdpi…) or architecture (arm64-v8a, armeabi-v7a…). permit’s configure cut up by using architecture:

ads


One APK report per each architecture will be generated and (optionally) one frequent document containing all architectures.


ads

If we might also configure splits by display density then APK documents for all density+structure mixtures could be generated (app-united kingdom-mdpiArmeabi-v7a-debug.apk, app-united kingdom-mdpiArm64-v8a-debug.apk, app-uk-hdpiArmeabi-v7a-debug.apk, app-united kingdom-hdpiArm64-v8a-debug.apk, and many others.).

ads

For debugging reason cut up can be needless, so we can configure splits most effective for our release builds. There are few approaches to approach this. we can bypass a parameter for Gradle build script to explicitly say that this construct must be cut up. in case you need to have capacity to allow or disable splitting for your construct server this is a manner to go. but we also can configure splits for release build through retrieving Gradle venture call while project is going for walks. this can permits us to decide if the present day Gradle challenge is a undertaking that creates launch build (eg. assamblePaidRelease) and make decision whatever we need to allow APK cut up or no longer:


ads

Now jogging assembleRelease duties for each flavour will generate more than one APK documents splited by means of CPU structure, even as walking assembleDebug tasks will generate unmarried APK file.

ads

version codes

Google Play keep does now not permit to add multiple APK documents with the identical version code. We need to ensure every APK has its personal specific versionCode.


ads

This code will permits us to override model code for every APK



to check if model code changed into properly generated we are able to open generated APK document using APK Analyzer and pick AndroidManifest.xml record to display it’s content material.

ads


We may also replace version call (eg. 3.13.0.seventy eight-arm64-v8a) to reflect modern architecture by editing extra versionNameOverride property inside the preceding code. We want to do it simplest while abiName isn't always null (we need to depart the name of ordinary APK intact)

ads

Which architectures to aid

We virtually need to help armeabi-v7a and arm64-v8a architectures because they have got around ninety nine% of marketplace propagation. With x86/x86_64 there may be an exciting case. From the cell market angle, they're insignificant and that is not likely to change within the destiny. however, Google is pushing builders to make their Android apps well suited with Chromebooks which might be ordinarily using Intel processors based on x86/x86_64 structure (meaning we can don't forget adding assist for it).

ads

most of the Chromebooks have Intel processors supporting Intel® VT-x, letting them run HAXM (the equal era we use to make apps in our emulators run a good deal quicker), so the app emulation is pretty rapid.

ads

Summing up here is a entire listing of Android architectures with usage recommendations:

ads

mips (deprecated)

mips64 (deprecated)

armeabi (deprecated)

armeabi-v7a (required — most popular structure in recent times)

arm64-v8a (required — more recent version of armeabi-v7a)

ads

x86 (optionally available, very constrained wide variety of gadgets, may be beneficial for debugging within the emulator)

ads

x86_64 (non-obligatory, very limited number of gadgets, can be beneficial for debugging in the emulator)

conclusion

ads

As we are able to see there are no golden rules here. the answer that we may also need relies upon on our native libraries length, potential to properly configure and control construct/launch manner and marketplace we want to goal.


ads

earlier than you make a decision approximately the usage of ABI filters or APK break up we ought to examine the scale of our local libraries, check our consumer base and decide how many customers will absolutely benefit from this modification. additionally we need to don't forget price of average overhead on our side.

ads

Post a Comment

0 Comments