Introduction
There are Android* devices running on processors supporting ARM* or x86 instruction set architectures (ISA). Different ISAs are not binary compatible and hence an application, if containing native code, should provide native libraries for each targeted ISA. The 'fat' Android* application packages ('fat' APK) is one of the distribution mechanisms for such applications.
This article provides the step by step instructions on building such 'fat' apk that includes the ISA-independent dex files for Dalvik* virtual machine (Dalvik, 2013) as well as the libraries for different ISA targets. It includes building the native application library for x86 using Intel® Integrated Native Developer Experience (INDE).
We will use hello-jni sample from the NDK r10 distribution for demonstration (which comes with Intel® INDE install).
Preparing the Build Environment
The following tools are necessary and these instructions should be follow in order:
1. Install:
2. Add this directory to the "PATH" environment variable:
For Windows environment, make sure to use short-folder name like "PROGRA~2" for "program files (x86)"
3. Create a new env-var:
4. Install:
5. Add this directory to the "PATH" environment variable:
Build from Command Line
This section provides the instructions on how to create the APK package to support Android devices with ARM* and x86 architectures from a command line build environment.
First open a command window or terminal window on Linux*; go to the Android NDK sample "hello-jni" directory [ndk-dir]\samples\hello-jni; and follow the steps below.
Note: All the tools noted in above section should be accessible from this window.
1.Configuring the Application
Run the following command from the "hello-jni" directory to generate a build.xml file that will be used to build the sample later.
$ android update project –target android-19 –name HelloJni –path . –subprojects
Note:
–target android-19: corresponds to to Android 4.4 (KITKAT) release.
2. Cleaning the Application Workspace
Use the following command to clean the whole workspace including libraries for all ISA architectures.
$ ant clean
$ ndk-build V=1 APP_ABI=all clean
Note:
. V=1 : prints all the commands as they are being executed.
. APP_ABI=all : forces cleanup of intermediate files for all targets. If this parameter is omitted only the armeabi target will be cleaned.
3. Building the Binary for ARM* Architecture
Use the command below to build the application binary for ARM architecture:
$ ndk-build APP_ABI=armeabi-v7a V=1 NDK_TOOLCHAIN=arm-linux-androideabi-4.8
Note:
. APP_ABI=armeabi-v7a : configures compilation for the ARM* target.
. NDK_TOOLCHAIN=arm-linux-androideabi-4.8 : overrides the default GNU* gcc 4.6 and uses gcc 4.8.
The application binary (libhello-jni.so ) is created at .\libs\armeabi-v7a\libhello-jni.so
4. Building the Binary for x86 Architecture with Intel Compiler
Use the command below to build the application binary with Intel compiler for x86 architecture:
$ ndk-build APP_ABI=x86 V=1 NDK_TOOLCHAIN=x86-icc NDK_APP.local.cleaned_binaries=true
Note:
. APP_ABI=x86 : configures compilation for the x86 architecture.
. NDK_TOOLCHAIN=x86-icc : overrides default compiler gcc 4.6 with Intel C/C++ compiler for Android.
. NDK_APP.local.cleaned_binaries=true : suppresses the library removal in the libs/armeabi directory. See notes at the bottom.
The application binary (libhello-jni.so ) is created at .\libs\x86\libhello-jni.so
5. Preparing Application package (APK)
After all of the binaries have been built for each Android target, check that the libs\[targetabi] directory contains required library for each targeted architecture.
To simplify the package creation and avoid package signing, use the following command to create a debug package:
$ ant debug
After that the new HelloJni-debug.apk package can be found in the .\bin directory. It can be run on x86* or ARM* emulators supporting API level 19 or higher provided by Android SDK.
The HelloJni-debug.apk package contains libraries for 2 targets: ARM EABI v7a and x86.
Build from Eclipse* IDE
1. Open Eclipse and load the sample [inde-dir]/IDEintegration/NDK/samples/hello-jni
2. Add Native Support to the project:
Note: If you see the console error "Unable to launch cygpath" after this step it can be ignored and will not affect your project.
3. Create a separate build configuration for each target platform and set build command
Right click on project and select Properties -> C/C++ Build -> "Manage configurations…"
Click New… to add the following new configurations based on Default configuration:
Still on the same Project Properties window, set Configuration to "x86_icc":
ndk-build APP_ABI=x86 NDK_TOOLCHAIN=x86-icc
Again on the same Project Properties window, set Configuration to "arm_gcc":
4. Clean the whole application workspace
5. Create Application.mk under [eclipse-workspace-dir]\HelloJni\jni directory is it does not exist, and make sure it has the following line:
NDK_APP.local.cleaned_binaries=true
6. Build the app binary for ARM* target using gcc and x86 target using Intel Compiler.
7. Create unsigned application packages
Right click on project and select Android Tools > Export Unsigned Application Package…
Note on Avoiding Cleanup of Binaries under .\libs\[targetabi]
Use of NDK_APP.local.cleaned_binaries=true parameter to suppress the removal of the previously built libraries may stop working in the future NDK releases. Please consult the [ndk-dir]/build/core/setup-app.mk makefile on how to disable delete actions for the target clean-installed-binaries.
For more such intel resources and tools from Intel, please visit the Intel® Developer Zone
Source: https://software.intel.com/en-us/android/articles/creating-an-x86-and-arm-apk-using-the-intelr-compiler-and-gnu-gcc