This topic applies to C/C++ on Windows* and OS X* host systems.
You can build applications for Intel architecture-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
Note
For Android* version 5.0 and later, you must use the -fpie and -pie options to generate position-independent code while building dynamically linked executables with the Intel® Compiler for ISS.
Install the 64-bit 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, the installation program integrates the compiler into the Android NDK build system automatically. Note that the Intel® C++ Compiler is the default compiler for Intel architecture-based targets for NDK revisions 9, 9b, 9c, 9d, 10d, and later.
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 using the compilervars file. See Using compilervars File for details.
Perform the following steps on a Windows* host system:
Open the setup environment window, from Start Menu > Intel System Studio 2016 for Linux and Android targets > Compiler and Performance Libraries > Command Prompt with Intel Compiler v16.0 > IA-32 Android [or Intel 64 Android].
A command prompt window opens up with the prompt at Program Files (x86)\IntelSWTools.
Change directory to \compilers_and_libraries_2016.x.yyy\windows\bin where the compilervars.bat is located.
Set up the environment for the Intel Compiler using the compilervars.bat file. See Using compilervars File for details.
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
Compiling Source Code
You are now ready to use icc/icpc from a command line in the build environment to compile C/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, with the Intel® C++ Compiler XX.x, use:
NDK_TOOLCHAIN=x86-iccXX.x.y.nnnwhere
XX
is the major version, 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_64 NDK_TOOLCHAIN:=x86_64-icc // 64-bit Linux 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