Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

4.3 How to Controlling APK Size When Using Native Libraries.

 ads

How to Controlling APK Size When Using Native Libraries.

ads

If you ever worked on decreasing your apk size you have to have come upon splitting the apk based on Density and alertness Binary Interface (ABI).

ads


in this put up we are able to apprehend what is ABI, troubles with the ABI split, and alternative way to keep away from those issues. If splitting APK is a new topic for you i'd advocate going thru the 

Wojtek Kaliciński

’s put up right here.

ads


what's ABI and the way it works?

The ABI defines, with extraordinary precision, how an software’s device code is supposed to interact with the gadget at runtime. You should specify an ABI for each CPU architecture you want your app to work with.

ads


as an example, Android helps the subsequent ABIs :

ads


mips, mips64, X86, X86–sixty four, arm64-v8a, armeabi, armeabi-v7a

In simple words all android devices have exclusive chipset, processors, and CPU architectures. programs uses the local library based totally at the CPU architecture of the cellphone as an example Google Pixel will use arm64-v8a version of the native lib and Google Nexus 5 will use armeabi-v7a model of the local lib.

ads


every time you upload any native library in your application it's going to have a .so file for all the supported CPU architectures. This will increase the apk length with the aid of a huge margin and the goal tool only desires one model of the library.


allow’s take an example to apprehend ABI in detail

i have created a sample app with one pastime and launcher icons.


ads


evaluation of the APK document

Now permit’s add a local library with multiple ABIs, for this demo I might be the use of Realm.


observe: This problem isn't always specific to realm, this is how all local library will behave on Android.


ads


APK info after including Realm

APK size is now 5MB from 74KB and all of us are like …

ads



allow’s take a look what occurred there.


ads


Realm distribution for distinct CPU structure

So basically realm adds .so file for five CPU architectures mips, X86, X86–64, armeabi-v7a, and arm64-v8a this will increase the apk length by means of 4.eight MB; ultimate ~130KB is expanded in dex size.

ads


in case you release this utility Google Pixel device will installation this 5MB apk wherein it needs only one version of the world lib (arm64-v8a) this is simply 947KB, that may be a big overhead. (it's going to even work nice with v7 model of realm that's simply 771KB, we are able to apprehend this quickly.)

ads


permit’s see how ABI split can assist us in keeping off this hassle

ABI split is basically telling gradle build machine to create more than one apks for the unique CPU architecture and encompass only applicable local libraries. The app module’s construct.gradle looks as if under with ABI cut up.


ads


Android application degree build.gradle report.

if you add this configuration in the application it's going to create a specific model of apk for all one-of-a-kind architectures as shown underneath.


ads


multiple APK files generated after permitting break up


remarkable proper! We went from 74KB to 5MB and came again to one.3 MB.


but but however….


even though we now have a tailor-made version of apk simplest with essential matters, those are five apk for one software and we haven’t even gone thru the apk splitting primarily based on the density (this selection generates person apk for xhdpi, xxhdpi, and xxxhdpi depending on the configuration) which is more useful than optimising for local library.

ads


generally we might need to cut up apk for at the least hdpi, xhdpi, and xxhdpi version of the utility so now we've got 15 APKs to launch. permit’s say you release an update of the utility each month then you have to preserve 15 apks and consider your customer/senior comes and tells you need to do sanity for each apk before release simply to be sure.

ads


there's even a bigger problem than this bulky renovation.


in case you are building the utility for the mass target audience, users in emerging marketplace like India wherein the mobile facts and WiFi isn't as cheap as other evolved countries, users percentage the software the usage of Bluetooth or warm-Spot through SHAREit or Xender and facet-load it.


ads


dialogue about the APK side loading

in case you cut up the apk using ABI split and a person with ARM architecture telephone stocks the application with someone with X86 architecture smartphone, the software will crash.


None people desires to be in that situation where apps are crashing left and right.

ads


It’s time to find a answer

there's a manner we are able to keep away from the above hassle by means of the usage of NDK abiFilters, do away with the ABI break up configuration and upload below code for your app module’s construct.gradle.


ads


build.gradle report with abiFilters configuration

What this options does is, it simplest keeps the local library of architectures mentioned in abiFilters. Now our 5MB apk is 2MB (no longer terrible right), we can avoid creating five APKs of 1MB or one APK of 5MB.


ads


APK with “armeabi-v7a” and “x86” libs

Wait a minute I just explained that changing some thing in ABI can bring about an unexpected end result on the person give up and now i'm suggesting to blindly cast off the ABIs, To understand that we want to go into the detail approximately every structure.

ads


TL;DR


element approximately CPU structure

in case you are still not certain about putting off these libraries, let me display you one example so that you can give you courage to do this. permit’s dig into Google Maps v9.fifty five.1 widespread apk — MinSDK: Android 4.three (Jelly Bean MR2, API 18).


ads


Google Maps uses splits with the aid of ABI and density (Google Maps has 17 apks for one launch) nevertheless their widely wide-spread apk best helps arm64-v8a, armeabi-v7a, X86, and X86–64.

ads


so you must take a name on assisting sixty four-bit libraries primarily based on length vs overall performance criteria but mips, mips-64, and armeabi need to be eliminated without any hesitation.

ads


element clarification approximately every architecture

armeabi, armeabi-v7a, and arm64-v8a

armeabi

armeabi is very old ARM primarily based architecture. for the reason that Android four.four, the CDD (compatibility definition) strictly calls for ARMv7 study CDD record right here.

CDD is specification furnished by Google to device manufacturers with every android release, it incorporates the minimal requirement to launch android devices with Google certification.


maximum of the tool manufactures shifted to armV7 earlier than Android four.4 so we will properly ignore this armeabi structure now.

ads


armeabi-v7a

that is the maximum commonplace architecture presently available. this is a should support ABI for all of the packages.

armeabi-v7a — 32bit — ARM Cortex-A5, ARM Cortex-A7, ARM Cortex-A8, ARM Cortex-A9, ARM Cortex-A12, ARM Cortex-A15, ARM Cortex-A17

arm64-v8a

this is the subsequent generation 64 bit ARM structure. all the flagship telephones uses this structure. beginning from Nexus 5x, Nexus 6P, Google Pixel all makes use of 64 bit ARM chipsets.

arm64-v8a — 64bit — ARM Cortex-A35, ARM Cortex-A53, ARM Cortex-A57, ARM Cortex-A72, ARM Cortex-A73

ads


aid of this ABI is non-compulsory as the devices can use armeabi-v7a model of the native library. There can be a mild performance hit using a 32 bit version of the library on sixty four bit processor however this must be avoidable thinking about that reality that we will shop ~1MB of APK size in above example.

ads


in case you are using a local library that's the core a part of your challenge and you want to give the exceptional experience to the consumer on Flagship phones then maybe you may include this ABI but for most of the apps this may be eliminated till we see the general public of devices adopting 64bit processors.

X86

Intel Processor-based devices, ASUS ZenFone2 being the most well-known tool of the lot in conjunction with many Lenovo telephones, application has to guide this.

X86–sixty four

ads


There aren't any android gadgets with sixty four-bit Intel processors available in the marketplace and even if there are few devices it could very well use the 32 bit model of the local library so X86–sixty four libs may be prevented in bundling.

mips and mips64

ads


There are not any android gadgets with MIPS structure in marketplace.

there has been one device which turned into imagined to be launched in 2016 but I haven’t located any facts aside from this newsletter First MIPS device and there is a thread approximately MIPS on Reddit.

ads


If making a decision to move down this course and filter the libraries, at the same time as liberating the software Google Play Console will display a warning like underneath however don’t fear it's miles just informing you about changes.


ads


So what are you waiting, pass ahead change your gradle file proper away.

ads

If you ever worked on decreasing your apk size you have to have come upon splitting the apk based on Density and alertness Binary Interface (ABI).

ads


in this put up we are able to apprehend what is ABI, troubles with the ABI split, and alternative way to keep away from those issues. If splitting APK is a new topic for you i'd advocate going thru the 

Wojtek Kaliciński

’s put up right here.

ads


what's ABI and the way it works?

The ABI defines, with extraordinary precision, how an software’s device code is supposed to interact with the gadget at runtime. You should specify an ABI for each CPU architecture you want your app to work with.

ads


as an example, Android helps the subsequent ABIs :

ads


mips, mips64, X86, X86–sixty four, arm64-v8a, armeabi, armeabi-v7a

In simple words all android devices have exclusive chipset, processors, and CPU architectures. programs uses the local library based totally at the CPU architecture of the cellphone as an example Google Pixel will use arm64-v8a version of the native lib and Google Nexus 5 will use armeabi-v7a model of the local lib.

ads


every time you upload any native library in your application it's going to have a .so file for all the supported CPU architectures. This will increase the apk length with the aid of a huge margin and the goal tool only desires one model of the library.


allow’s take an example to apprehend ABI in detail

i have created a sample app with one pastime and launcher icons.


ads


evaluation of the APK document

Now permit’s add a local library with multiple ABIs, for this demo I might be the use of Realm.


observe: This problem isn't always specific to realm, this is how all local library will behave on Android.


ads


APK info after including Realm

APK size is now 5MB from 74KB and all of us are like …

ads



allow’s take a look what occurred there.


ads


Realm distribution for distinct CPU structure

So basically realm adds .so file for five CPU architectures mips, X86, X86–64, armeabi-v7a, and arm64-v8a this will increase the apk length by means of 4.eight MB; ultimate ~130KB is expanded in dex size.

ads


in case you release this utility Google Pixel device will installation this 5MB apk wherein it needs only one version of the world lib (arm64-v8a) this is simply 947KB, that may be a big overhead. (it's going to even work nice with v7 model of realm that's simply 771KB, we are able to apprehend this quickly.)

ads


permit’s see how ABI split can assist us in keeping off this hassle

ABI split is basically telling gradle build machine to create more than one apks for the unique CPU architecture and encompass only applicable local libraries. The app module’s construct.gradle looks as if under with ABI cut up.


ads


Android application degree build.gradle report.

if you add this configuration in the application it's going to create a specific model of apk for all one-of-a-kind architectures as shown underneath.


ads


multiple APK files generated after permitting break up


remarkable proper! We went from 74KB to 5MB and came again to one.3 MB.


but but however….


even though we now have a tailor-made version of apk simplest with essential matters, those are five apk for one software and we haven’t even gone thru the apk splitting primarily based on the density (this selection generates person apk for xhdpi, xxhdpi, and xxxhdpi depending on the configuration) which is more useful than optimising for local library.

ads


generally we might need to cut up apk for at the least hdpi, xhdpi, and xxhdpi version of the utility so now we've got 15 APKs to launch. permit’s say you release an update of the utility each month then you have to preserve 15 apks and consider your customer/senior comes and tells you need to do sanity for each apk before release simply to be sure.

ads


there's even a bigger problem than this bulky renovation.


in case you are building the utility for the mass target audience, users in emerging marketplace like India wherein the mobile facts and WiFi isn't as cheap as other evolved countries, users percentage the software the usage of Bluetooth or warm-Spot through SHAREit or Xender and facet-load it.


ads


dialogue about the APK side loading

in case you cut up the apk using ABI split and a person with ARM architecture telephone stocks the application with someone with X86 architecture smartphone, the software will crash.


None people desires to be in that situation where apps are crashing left and right.

ads


It’s time to find a answer

there's a manner we are able to keep away from the above hassle by means of the usage of NDK abiFilters, do away with the ABI break up configuration and upload below code for your app module’s construct.gradle.


ads


build.gradle report with abiFilters configuration

What this options does is, it simplest keeps the local library of architectures mentioned in abiFilters. Now our 5MB apk is 2MB (no longer terrible right), we can avoid creating five APKs of 1MB or one APK of 5MB.


ads


APK with “armeabi-v7a” and “x86” libs

Wait a minute I just explained that changing some thing in ABI can bring about an unexpected end result on the person give up and now i'm suggesting to blindly cast off the ABIs, To understand that we want to go into the detail approximately every structure.

ads


TL;DR


element approximately CPU structure

in case you are still not certain about putting off these libraries, let me display you one example so that you can give you courage to do this. permit’s dig into Google Maps v9.fifty five.1 widespread apk — MinSDK: Android 4.three (Jelly Bean MR2, API 18).


ads


Google Maps uses splits with the aid of ABI and density (Google Maps has 17 apks for one launch) nevertheless their widely wide-spread apk best helps arm64-v8a, armeabi-v7a, X86, and X86–64.

ads


so you must take a name on assisting sixty four-bit libraries primarily based on length vs overall performance criteria but mips, mips-64, and armeabi need to be eliminated without any hesitation.

ads


element clarification approximately every architecture

armeabi, armeabi-v7a, and arm64-v8a

armeabi

armeabi is very old ARM primarily based architecture. for the reason that Android four.four, the CDD (compatibility definition) strictly calls for ARMv7 study CDD record right here.

CDD is specification furnished by Google to device manufacturers with every android release, it incorporates the minimal requirement to launch android devices with Google certification.


maximum of the tool manufactures shifted to armV7 earlier than Android four.4 so we will properly ignore this armeabi structure now.

ads


armeabi-v7a

that is the maximum commonplace architecture presently available. this is a should support ABI for all of the packages.

armeabi-v7a — 32bit — ARM Cortex-A5, ARM Cortex-A7, ARM Cortex-A8, ARM Cortex-A9, ARM Cortex-A12, ARM Cortex-A15, ARM Cortex-A17

arm64-v8a

this is the subsequent generation 64 bit ARM structure. all the flagship telephones uses this structure. beginning from Nexus 5x, Nexus 6P, Google Pixel all makes use of 64 bit ARM chipsets.

arm64-v8a — 64bit — ARM Cortex-A35, ARM Cortex-A53, ARM Cortex-A57, ARM Cortex-A72, ARM Cortex-A73

ads


aid of this ABI is non-compulsory as the devices can use armeabi-v7a model of the native library. There can be a mild performance hit using a 32 bit version of the library on sixty four bit processor however this must be avoidable thinking about that reality that we will shop ~1MB of APK size in above example.

ads


in case you are using a local library that's the core a part of your challenge and you want to give the exceptional experience to the consumer on Flagship phones then maybe you may include this ABI but for most of the apps this may be eliminated till we see the general public of devices adopting 64bit processors.

X86

Intel Processor-based devices, ASUS ZenFone2 being the most well-known tool of the lot in conjunction with many Lenovo telephones, application has to guide this.

X86–sixty four

ads


There aren't any android gadgets with sixty four-bit Intel processors available in the marketplace and even if there are few devices it could very well use the 32 bit model of the local library so X86–sixty four libs may be prevented in bundling.

mips and mips64

ads


There are not any android gadgets with MIPS structure in marketplace.

there has been one device which turned into imagined to be launched in 2016 but I haven’t located any facts aside from this newsletter First MIPS device and there is a thread approximately MIPS on Reddit.

ads


If making a decision to move down this course and filter the libraries, at the same time as liberating the software Google Play Console will display a warning like underneath however don’t fear it's miles just informing you about changes.


ads


So what are you waiting, pass ahead change your gradle file proper away.

ads


Post a Comment

0 Comments