48

I have a few native libraries that are fairly big and bloating the application binary size. I looked into APK splitting but maintaining and QAing multiple APKs is not something I want to do.

So I'd like to exclude unused architectures in my release build flavour using the ndk.abiFilters Gradle property. (The debug builds I want to leave alone so that I can run the HAXM-accelerated emulator on x86).

I was thinking of just having armeabi-v7a and arm64-v8a in my release flavour, but I'm not sure whether it is worth worrying about the market share of the other architectures I'm dropping. After a lot of looking around I cannot find any reference to market share of ARMv6 (armeabi), MIPS, x86 or x86_64. My intuition tells me that the latter three are almost non-existent, but I'm not sure about ARMv6.

I found this link on a forum that has a list of phones that use various architectures. Is there something more reliable somewhere? Maybe with % of users similar to the Android version dashboard?

Anything else I may miss if I just build my native libs for armeabi-v7a and arm64-v8a (or armeabi, armeabi-v7a and arm64-v8a)?

kos
  • 1,770
  • 2
  • 19
  • 41

4 Answers4

46

First off, if you're worring about binary size, you don't really need arm64-v8a, all those devices can run the armeabi-v7a binaries just fine. Only if you really need to cram the last extra performance out of it, it might be worthwhile.

As for armeabi and ARMv6; Android itself doesn't officially support it any longer, since Android 4.4 (October 2013) - and since Android 4.0 it should be much less common (from that version, AOSP source requires modifications to still build for ARMv6). So in practice, if you aren't supporting versions below 4.4, you can drop that one without any significant loss.

Also, for x86; many of those devices ship with surprisingly decent emulation of arm binaries, so those can manage with the armeabi-v7a version just fine as well.

EDIT: The above was written in 2015; these days Play Store requires that apps include support for arm64-v8a. But these days the next question is more about whether you need to include armeabi-v7a at all, or if the market share of 32 bit devices is small enough to drop support for.

mstorsjo
  • 12,983
  • 2
  • 39
  • 62
  • 4
    so are you saying armeabi-v7a is all one really needs unless supporting < 4.4 or needing extra perf from v8a? – Chase Florell Apr 26 '17 at 22:22
  • 3
    Pretty much. Some x86 devices might not support arm binaries but I think most of them do. There are also mips devices, and I don't think those include arm emulation. They're pretty rare though (probably one order of magniture more rare than x86 devices although I didn't find any statistics to back it up). – mstorsjo Apr 27 '17 at 05:57
  • @mstorsjo can you please explain how to use armeabi-v7a library file for all architectures? In my current approach, I have to copy library to jniLibs/armeabi, jniLibs/armeabi-v7a and jniLibs/x86, which makes apk larger. – Lahiru Chandima May 23 '17 at 17:40
  • I tried substituting armeabi-v7a for arm64-v8a, but my application kept crashing. I had to keep arm64-v8a in for it to run. – Mateen Ulhaq Jul 23 '17 at 12:51
  • 1
    There are actually 0 devices on the Play Store with Android 4.0 or higher with just `ameabi` support (and no `armeabi-v7a`). Likewise, there are zero which support `mips`. Therefore, you can safely drop these 2 even if your minSdkVersion is only 14. – Cristan Jun 24 '18 at 08:32
  • @mstorsjo Is this still the case 3 years later? – ClassA Oct 07 '18 at 05:17
  • 4
    Almost; things have changed a little since then, but not much. Even if you technically might not need 64 bit support, play store will require apps to provide a version for that, starting August 2019. ARMv5/6 is completely deprecated now (deprecated since NDK r16, removed in r17). I don't think there have been any significant amount of new x86 Android devices either - Intel has stopped their efforts with Atom for phones/tablets. – mstorsjo Oct 07 '18 at 18:16
32

Including additional architectures will no longer have any impact on the binary size when using app bundles, as in that case Google Play will serve each device only the binaries that apply to that particular device. Not only that, but also application updates will be way smaller and faster.

Leaving the previous information for projects still not using app bundles:

  • Unfortunately, the Android Dashboard, as useful as it is, does not provide architecture information, nor does Google Analytics.

  • The Unity statistics used to provide statistics per architecture and CPU features. Note, however, that these are not general statistics, but only cover users of Unity applications/games. The information doesn't seem to be available in a public link anymore, so I have replaced the direct links with the latest snapshots in archive.org.

Jose Gómez
  • 3,110
  • 2
  • 32
  • 54
22

I was stuck with this problem when using Mapbox, then later found this article which was very useful.

Based on the below picture you just need armeabi-v7a and x86. Then based on Jose Gómez answer, I only added armeabi-v7a and didn't have any problem at all.

So add this line to your app.gradle

android {
 defaultConfig {
        //other configs
        ndk {
            abiFilters "armeabi-v7a"
        }
    }
}

If you're still worried about 2% - 3% of those who use x86 architecture, like ASUS ZenFone and lenovo phones then use this config instead in app.gradle

ndk {
    abiFilters "armeabi-v7a", "x86"
}

Also for genymotion emulators you should use x86 architecture

enter image description here

UPDATE

If you get this error while publishing the apk in play store

enter image description here

Then use this

ndk {
    abiFilters "armeabi-v7a", "arm64-v8a"
}

And finally, I suggest you use app bundle for releasing the APK

Sparkzz
  • 367
  • 5
  • 14
Radesh
  • 13,084
  • 4
  • 51
  • 64
4

When I read @mstorsjo answer I was a little bit confused how to really use only one (or two) native libs, even though it's quite simple and straightforward. Therefore, I will give here an example and some more explanation (based on my further research).

For each supported architecture we have to create a specific folder in the jniLibs folder and drop the .so file there. As an example, for supporting armeabi-v7a (32bit) and arm64-v8a (64bit):

|--app
|--|--src
|--|--|--main 
|--|--|--|--jniLibs 
|--|--|--|--|--armeabi-v7a 
|--|--|--|--|--|--.so Files 
|--|--|--|--|--arm64-v8a 
|--|--|--|--|--|--.so Files 

With armeabi-v7a you support more than 90% of the available devices, but since it is 32bit architecture, running it on 64bit devices will result in an loss of performance (20-30%) {1}. For each specific case it can be quite handy to check the actual amount of supported devices, which can be done within the Google Play Console in the Release management > Device catalog section, by specifying ABI as filter.

Attention

When you don't add binaries for all architectures you have to be aware of the following:

If your app contains any other native libraries, you'll have to make sure you only have the same versions of them as well. That is due to Android demanding that all loaded native libraries be built for the same architecture. For example, if the first native library loaded is armeabi-v7a, Android will look ONLY for armeabi-v7a libraries on all System.loadLibrary() calls after that. If it doesn't find that exact architecture, it'll throw the java.lang.UnsatisfiedLinkError exception. {1}

I ran into this problem because some of my dependencies used native libraries, whereby armeabi-v7a couldn't be loaded anymore.

goemic
  • 1,092
  • 12
  • 24