This topic applies to C/C++ on Linux* and Windows* host systems.
You can build applications for x86-based Android* devices in two ways:
Using the Intel® C++ Compiler toolchain as a standalone compiler
Enabling the Intel toolchain within the Android NDK build system
To do this, install the Android* NDK from http://developer.android.com/sdk/ndk/index.html or the Android* Open Source Project (AOSP) from http://source.android.com/. Refer to the Release Notes for supported NDK versions.
When you install the Intel® C++ Compiler (ICC), the installation program integrates the compiler into the Android NDK build system automatically. icc is the default compiler for Intel architecture-based targets for NDK revisions 9, 9b, 9c and 9d.
Using Intel® C++ Compiler Toolchain as Standalone Compiler
The Intel C++ Compiler requires a GNU compiler toolchain for the Android OS to work.
Perform the following steps on Linux* host systems:
Open a terminal window.
Set up the environment for the Intel Compiler with the following command:
$ source [icc-install-dir]/bin/compilervars.sh
where
[icc-install-dir]
is:/opt/intel/system_studio_2015.0.nnn/
Perform the following steps on a Windows* host system:
Open the setup environment window, on Windows* 8.x, from Start Menu > Programs > Intel® System Studio > Command Prompt > IA-32.
Or
Open a command window to setup the environment manually.
Set up the environment for the Intel Compiler with the following command:
>>[icc-install-dir]\bin\compilervars.bat
where
[icc-install-dir]
is a directory where compiler installs.By default, it is C:\Intel\system_studio_2015.0.nnn/, where
nnn
is the package build number.
If you see errors requesting to set up ANDROID_SYSROOT and ANDROID_GNU_X86_TOOLCHAIN environment variables, the possible reason is that you used an unsupported NDK version during installation. In such a case, you can set up the environment variables manually.
Using the NDK environment:
If you installed the 32-bit version of the Android NDK, set the environment variables as follows:
//On Linux* system $ export NDK_DIR=[Android NDK-install-directory] $ export ANDROID_SYSROOT=$NDK_DIR/platforms/android-18/arch-x86 $ export ANDROID_GNU_X86_TOOLCHAIN=$NDK_DIR/toolchains/x86-4.6/prebuilt/linux-x86
//On Windows* system>>set NDK_DIR=[Android NDK-install-directory]>>set ANDROID_SYSROOT=%NDK_DIR%\platforms\android-18\arch-x86>>set ANDROID_GNU_X86_TOOLCHAIN=%NDK_DIR%\toolchains\x86-4.6\prebuilt\windows-x86
If you installed the 64-bit host version of the Android NDK, set the environment variables as follows :
//On Linux* system $ export NDK_DIR=[Android NDK-install-directory] $ export ANDROID_SYSROOT=$NDK_DIR/platforms/android-18/arch-x86 $ export ANDROID_GNU_X86_TOOLCHAIN=$NDK_DIR/toolchains/x86-4.6/prebuilt/linux-x86_64
//On Windows* system>>set NDK_DIR=[Android NDK-install-directory]>>set ANDROID_SYSROOT=%NDK_DIR%\platforms\android-18\arch-x86>>set ANDROID_GNU_X86_TOOLCHAIN=%NDK_DIR%\toolchains\x86-4.6\prebuilt\windows-x86_64
Using the AOSP environment:
If you are using the AOSP environment on a Linux* host, set the variables as follows:
export TOPDIR= #set to the AOSP root directory (example: /export/JB_WW36) export ANDROID_SYSROOT=$TOPDIR/prebuilts/ndk/8/platforms/android-17/arch-x86 export ANDROID_GNU_X86_TOOLCHAIN=$TOPDIR/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6
You are now ready to use icc from a command line in the build environment to compile C source code and icpc to compile C++ source code.
Here is an example on Linux* host:
$ cd $NDK_DIR/samples/hello-jni/jni $ icc -platform=android -c hello-jni.c $ icc -platform=android –shared -o libhello-jni.so hello-jni.o
Enabling Intel Toolchain within Android NDK Build System
To understand how to enable the Intel toolchain within the Android* NDK build system, follow the steps to build the hello-jni
sample application that ships with the Android NDK. You can locate the sample in $NDK_DIR/samples/hello-jni/jni/.
Build the sample application with the Intel® C++ Compiler either from the command line or using the *.mk file. In either approach, you need to configure APP_ABI if you want to use ICC. If multiple versions of the Intel compiler are installed, a full compiler package version can be specified. For example:
NDK_TOOLCHAIN=x86-icc15.x.y.nnnwhere
x
is the minor version, y
is the update number, and nnn
is the package build number.Open the terminal window and navigate to the
jni
folder of the sample:cd $NDK/samples/hello-jni
Enter the following command:
$ $NDK_DIR/ndk-build V=1 -B APP_ABI=x86 NDK_TOOLCHAIN:=x86-icc // 32-bit Linux host
$ $NDK_DIR/ndk-build V=1 -B APP_ABI=x86_64 NDK_TOOLCHAIN:=x86_64-icc // 64-bit Linux host
>>%NDK_DIR%\ndk-build V=1 -B APP_ABI=x86 NDK_TOOLCHAIN:=x86-icc // 32-bit Windows host
>>%NDK_DIR%\ndk-build V=1 -B APP_ABI=x86_64 NDK_TOOLCHAIN:=x86_64-icc // 64-bit Windows host
where:
V=1 enables verbose output (optional)
-B means rebuild all (optional)
APP_ABI indicates target architecture.
Open or create the Application.mk file in your application’s jni folder at $NDK_DIR/samples/hello-jni/jni/.
Add the following lines in Application.mk:
For 32-bit targets:
APP_ABI:=x86 NDK_TOOLCHAIN:=x86-icc
For 64-bit targets:
APP_ABI:=x86_64 NDK_TOOLCHAIN:=x86_64-icc
Run the command to build the application:
$ $NDK_DIR/ndk-build V=1 –B // on Linux* host
>>%NDK_DIR%\ndk-build V=1 –B // on Windows* host