Intel® Learning Lab (white papers, articles and more)
Intel® C++ Compiler for Android* is compatible with the gcc compiler in the Android NDK and can be used to develop applications for x86-based devices that use Android OS. Software developers can use the Compiler from Windows*, OS X* or Linux* hosts. Intel C++ Compiler for Android is compatible with, and requires, the Android NDK, which can be found at http://developer.android.com/sdk/ndk/index.html.
Intel C++ Compiler for Android is based on the Intel® C++ Compiler for Linux*, version 14.0. Not all features in the Linux compiler are available in the Intel C++ Compiler for Android. See the Release Notes for differences. Developers can take comfort in knowing that just about anything you can do in your gcc source code for your Android applications, you can also do with the Intel C++ Compiler for Android. You can even build applications that use gcc for devices based on ARM* Architecture and icc for devices based on Intel Architecture. It is highly compatible with gcc and tools in the NDK and SDK, while delivering outstanding app performance.
For this release of Intel C++ for Android, we offer documentation that is common across several Intel C++ product offerings, including, for example, Intel® C++ Composer XE, which is an offering for developers working on high-performance computing – applications that might be running on large, multi-processor servers or even compute-clusters.
This document presents getting-started information specific to the Intel® C++ Compiler for Android* and replaces the Getting Started section in the User and Reference Guide for Intel® C++ Compiler, version 14.0.
Throughout this Guide, we will refer to the Intel® C++ Compiler for Android* as Intel® C++ Compiler, Compiler, or icc.
You can develop 32-bit applications for x86-based Android devices in two ways. You can enable the icc toolchain with the Android NDK build system or you can use the icc toolchain as a standalone compiler. The following sections provide general guidelines for each method.
After you install the Intel® C++ Compiler for Android*, the installation program integrates the Intel® C++ Compiler into the Android NDK build system automatically. ICC will be the default compiler for x86 targets after installation. For details, see the Installation Guide.
The Android NDK ships with sample applications that can be found in the "samples" directory under the Android NDK directory after installation of NDK.
Now let us see how to build for a target with NDK. We will use the "hello-jni" sample application that ships with the Android NDK. It is in the "samples" directory under the "NDK" directory. In our example, NDK is installed to "Applications".
The screenshot below shows an example of what this might look like in the OS X* Finder:
Figure 1. The "hello-jni" app can be found in the "samples"
directory under the Android NDK directory. Stated differently,
the path is: "$NDK_DIR/samples/hello-jni/jni".
You can build the sample application with the Intel® C++ Compiler using one of the options below:
Open the terminal window and navigate to the "jni" folder of the sample.
Use the following command:
$ $NDK_DIR/ndk-build V=1 -B APP_ABI=x86
V=1 enables verbose output (optional)
-B means rebuild all (optional)
APP_ABI indicates target architecture.If you want to target all architectures supported by the NDK change this to "APP_ABI=all".
a. Open or create the “Application.mk” file in your application’s "jni" folder at "$NDK_DIR/samples/hello-jni/jni/"
b. Add the following lines in the Application.mk:
c. Run the below command to build the application:
$ $NDK_DIR/ndk-build V=1 –B
In either approach, you need to configure APP_ABI if you want to use ICC. If multiple versions of Intel compiler are installed, a full compiler package version can be specified. For example:
where "x" is the minor version, "y" is the update number, "nnn" is the package build number.
By default, the NDK is configured to build an application for debugging within Eclipse*, and all optimizations are turned off. When the code is ready for deployment, you need to compile it for performance.
APP_CFLAGS:=-xATOM_SSSE3 –O3 –ipo
Note that the APP_OPTIM and APP_CFLAGS can be given as arguments in building from the command line. Here is an example:
$ ndk-build V=1 -B APP_ABI=x86 APP_OPTIM=release APP_CFLAGS=”-xATOM_SSSE3 –O3 -ipo”
For further details, refer to the “High-Level Optimizations (HLO)” and “Interprocedural Optimization (IPO)” sections in the Intel® C++ Compiler XE 14.0 User and Reference Guides supplied with the package or on the web.
$ source [icc-install-dir]/bin/compilervars.sh
where [icc-install-dir] is any directory you choose to install the compiler. By default, it is:
where “x” is the minor version, “y” is the update number, “nnn” is the package build number.
If you choose the default installation directory, use the following command:
$ source /opt/intel/cc_android_14.x.y.nnn/bin/compilervars.sh
If you saw errors requesting to set up ANDROID_SYSROOT and ANDROID_GNU_X86_TOOLCHAIN environment variables, the possible reason is that you are using an unsupported NDK version while installation. You can still set up the environment variables manually.
If you installed the 32-bit version of the Android NDK, set the environment variables as follows:
$ 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/darwin-x86
If you installed the 64-bit version of Android NDK, set the environment variables as follows:
$ 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/darwin-x86_64
You are now ready to use icc from a command line in the build environment where you can use “icc” to compile C source code and “icpc” to compile C++ source code. Here is an “icc” example:
$ cd $NDK_DIR/samples/hello-jni/jni
$ icc -c hello-jni.c
$ icc –shared -o libhello-jni.so hello-jni.o
This section explains how to configure Eclipse and Eclipse projects to use icc for Android. Note, that you should have the Android Developer Toolkit (ADT) installed as a prerequisite. The ADT includes SDK components and a version of the Eclipse IDE with built-in Android Developer Tools. Follow the instructions below to configure Eclipse and Eclipse projects to use Intel C++ Compiler.
OS X* Finder displaying the Android Developer
(ADT) installation with focus on the Eclipse IDE start-up icon.
Figure 3. Eclipse showing the "ADT" menu, from which you select "Preferences".
Figure 4. "Preference" pop-up window focused on the Android NDK selection.
This enables users to specify the NDK Location.
a) From the Eclipse menu, select File > New > Project…
Figure 5. Creating a new project from NDK sample code. From the "File" menu, select "Project..."
b) A pop-up window will appear called New Project. Select Android Project from Existing Code and click Next.
Figure 6. Creating a new project from NDK sample code. In the resulting pop-up, highlight "Android Project
from Existing Code" and click "Next>".
c) Import Project window opens. Browse to "[ndk-dir]/samples/hello-jni" directory, check the Copy projects into workspace check-box, and then click Finish.
Figure 7. In the "Import Projects" pop-up window, confirm the project you want to load and make sure you
put a check mark to "Copy projects into workspace". Then click "Finish."
This will open the newly created project in the Project Explorer:
Figure 8. The new created project opens in the Project Explorer.
a) To add “Native Support” to the project, right-click on the project name in the “Project Explorer” window, select Android Tools > Add native Support …
9. Adding Native Support to a project loaded into Eclipse. Right-click
the project name, go to "Android Tools" and click "Add Native Support…"
b) A dialog opens asking for the Library Name. Set the library name to “hello-jni” as shown below:
Figure 10. Set the library name to "hello-jni". Click "Finish".
The application can now be tested on any x86-based Android device including an x86-based Android Virtual Device (AVD).
Read the article Using Advanced Intel(R) C++ Compiler Features for Android* Applications for details.
Read the online article Building Native Android* Apps Using Intel(R) C++ Compiler in Android Studio* for latest status. Please, note that the Android Studio support is a preview feature.
Read the Release Notes and Installation Guide for information on the product installation, new and changed features, and issues that are not described in the product documentation.
Read information in the User and Reference Guide for the Intel® C++ Compiler 14.0 supplied with this package.
Access the Intel(R) C++ Compiler for Android* Help from the Eclipse* IDE: start Eclipse*, go to Help>Help Content, find Intel(R) C++ Compiler for Android* Help in TOC.
Visit Intel® Developer Zone for more information about Intel® C++ Compiler for Android* OS.
Read the NDK documentation under $NDK/docs.
Contact your Intel representative for more information on Intel® C++ Compiler for Android* OS.
Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.
Notice revision #20110804
INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
A "Mission Critical Application" is any application in which failure of the Intel Product could result, directly or indirectly, in personal injury or death. SHOULD YOU PURCHASE OR USE INTEL'S PRODUCTS FOR ANY SUCH MISSION CRITICAL APPLICATION, YOU SHALL INDEMNIFY AND HOLD INTEL AND ITS SUBSIDIARIES, SUBCONTRACTORS AND AFFILIATES, AND THE DIRECTORS, OFFICERS, AND EMPLOYEES OF EACH, HARMLESS AGAINST ALL CLAIMS COSTS, DAMAGES, AND EXPENSES AND REASONABLE ATTORNEYS' FEES ARISING OUT OF, DIRECTLY OR INDIRECTLY, ANY CLAIM OF PRODUCT LIABILITY, PERSONAL INJURY, OR DEATH ARISING IN ANY WAY OUT OF SUCH MISSION CRITICAL APPLICATION, WHETHER OR NOT INTEL OR ITS SUBCONTRACTOR WAS NEGLIGENT IN THE DESIGN, MANUFACTURE, OR WARNING OF THE INTEL PRODUCT OR ANY OF ITS PARTS.
Intel may make changes to specifications and product descriptions at any time, without notice. Designers must not rely on the absence or characteristics of any features or instructions marked "reserved" or "undefined". Intel reserves these for future definition and shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them. The information here is subject to change without notice. Do not finalize a design with this information.
The products described in this document may contain design defects or errors known as errata which may cause the product to deviate from published specifications. Current characterized errata are available on request.
Contact your local Intel sales office or your distributor to obtain the latest specifications and before placing your product order.
Copies of documents which have an order number and are referenced in this document, or other Intel literature, may be obtained by calling 1-800-548-4725, or go to: http://www.intel.com/design/literature.htm.
Intel processor numbers are not a measure of performance. Processor numbers differentiate features within each processor family, not across different processor families. See http://www.intel.com/products/processor_number/ for details.
Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice. Notice revision #20110804
Intel, Intel Atom, and Intel Core are trademarks of Intel Corporation in the U.S. and/or other countries.
*Other names and brands may be claimed as the property of others.
Copyright © 2014, Intel Corporation. All rights reserved.