This guide details the steps required to add x86 architecture support for applications using the NDK build process.
Recent NDK Release
The process detailed in this guide assumes development occurs with a recent version of Google’s* NDK. Any release after revision 6b (August 2011) will be compatible with the process detailed below. However, the latest NDK will always have the latest bug fixes, including performance and compatibility fixes.
Architecture Dependent Features
The target application’s native shared/static libraries cannot take advantage of processor specific extensions (ARM NEON*, etc.). Doing so will require those modules to be re-written to utilize an x86 equivalent extension before this process can be used.
The x86 instruction set is the same as the desktop (up to SSSE3). Common algorithm optimized for x86 on the desktop can be reused for Android* apps (e.g. skinning with SSE, asm, etc).
Android NDK Build Process
This guide assumes the application uses the build process supplied by the Android NDK. If the project utilizes a custom build process, supporting x86 architecture is still possible using the Android NDK’s standalone tool chain. The process of setting up the standalone tool chain is outside the scope of this document. For more information setting up this build process, see the NDK documentation located at “<ANDROID_NDK_ROOT >/docs/STANDALONE-TOOLCHAIN.html”
Setting up the Build Tools
When using the build system provided by the Android NDK, targeting x86 is as simple as adding x86 to the list of target architectures in the build process. This is done by modifying the Application.mk file inside the project.
Updating the Target ABI
To setup up the NDK build system to target x86:
- Create or modify the Application.mk file under “<PROJECT_ROOT >/jni” if one does not exist
- Open the file and add, or modify, the line which assigns the APP_ABI variable as follows:
a. If it exists, add “x86” as one of the targets (ex: APP_ABI := armeabi x86)
b. If the APP_ABI variable is not present, add the following line to target both ARMv5TE and x86 architectures.
APP_ABI := armeabi x86
Rebuilding the Application
Whenever the APP_ABI targets are modified, the dependent shared and static libraries must be rebuilt (perform a clean build). Additionally, if the application uses any 3rd party middleware, the middleware must also be rebuilt for x86, or linked with x86-specific libraries.
Validating with the Emulator
Intel provides a driver which allows the Android emulator to utilize the native x86 hardware. The tool is called Intel® Hardware Accelerated Execution Manager (Intel® HAXM) and works on Windows, Mac OS and Linux platforms. The tool can be obtained through the SDK manager by downloading the option under the “Extras” subsection and checking “Intel x86 Emulator Accelerator (HAXM).”
The installer will be placed under “<ANDROID_SDK_ROOT >\extras\intel”
After installation, startup the Android Virtual Device manager, and create a new target. Make sure under the CPU/ABI dropdown “Intel Atom (x86)” is selected as well as the “Use Host GPU” checkbox.
To verify the installation, the following line should be shown in the emulator’s log when launched:
“HAX is working and emulator runs in fastvirt mode”
Install and run the compiled APK on the newly created virtual device to verify the process.
There are two options when publishing .APKs targeting multiple architectures. The first, includes the shared/static libraries for all the target architectures inside a single .APK file. This is the preferred method. If however the resulting .APK is too large to be submitted to the Google Play Store, it’s also possible to generate a separate .APK for each architecture. There are a number of requirements to ensure that both .APKs represent the same application. For more details on the process of handling multiple .APK files, see the documentation located at http://developer.android.com/google/play/publishing/multiple-apks.html
Related Articles and Resources
- Options for Releasing Native Android* Apps for Intel® Architecture (x86)
- How to Use the Intel® Hardware Accelerated Execution Manager (Intel® HAXM) Android* Emulator with Google APIs
- Development and Optimization for NDK-based Android Game Application on Platforms based on Intel® Architecture
- Deploying Apps to Google Play
About the Author
Chris Kirkpatrick is a Software Engineer in the Software and Services Group of Intel Corporation where he enjoys specializing in computer graphics and software optimization. In his leisure time, Chris enjoys reading and writing music.