Supporting multiple CPU architectures
Android NDK supports different CPU architectures such as ARMv5TE and ARMv7-based devices, x86, and MIPS (big-endian architecture). We can create fat binaries that can run on any of the supported platforms.
Getting ready
Find out the architecture of your Android-based device. You can do it using the adb
command as follows:
>adb shell cat /proc/cpuinfo
How to do it...
The following are the two approaches to pick an appropriate set of CPU architectures:
- By default, the NDK will generate the code for ARMv5TE-based CPUs. Use the parameter
APP_ABI
inApplication.mk
to select a different architecture, for example (use only one line from the following list):APP_ABI := armeabi-v7a APP_ABI := x86 APP_ABI := mips
- We can specify multiple architectures to create a fat binary that will run on any of them through the following command:
APP_ABI := armeabi armeabi-v7a x86 mips
There's more...
The main pitfall of the fat binaries is the resulting .apk
size, as separate native code versions are compiled for each of the specified architectures. If your application heavily uses third-party libraries, the package size can become an issue. Plan your deliverables wisely.