Click here to Skip to main content
15,918,177 members
Articles / Mobile Apps / Android

Building Native Android Apps Using Intel(R) C++ Compiler in Android Studio 1.0.1

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
7 Apr 2015CPOL5 min read 15.7K   18  
The steps below provide a general description of how to setup, build, and run a new native application in Android Studio 1.0.1.

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Intel® Developer Zone offers tools and how-to information for cross-platform app development, platform and technology information, code samples, and peer expertise to help developers innovate and succeed. Join our communities for Android, Internet of Things, Intel® RealSense™ Technology, and Windows to download tools, access dev kits, share ideas with like-minded developers, and participate in hackathon’s, contests, roadshows, and local events.

Table of Contents:


The current Android Studio* release is 1.0.1 at the time of this writing. The Intel® C++ Compiler for Android as part of Intel® Integrated Native Developer Experience (Intel® INDE) is supporting Android Studio 1.0.1 in Intel INDE 2015 Update 1. Since Android Studio 1.0.1 does not support Android NDK, instructions have been provided in this article with steps on how to build a native Android* app using Android NDK r10d and Intel C++ Compiler for Android.

Android Studio uses Gradle for its build system. At the time of this writing Gradle invokes the NDK build system as part of the build process. With Android NDK r10 and later, the Intel® C++ Compiler for Android (ICC) is no longer the default compiler in the NDK build system after Intel INDE is installed.

The steps below provide a general description of how to setup, build, and run a new native application in Android Studio 1.0.1.

If you have Android Studio* 0.8.6, please refer to this article Building Native Android* Apps Using Intel(R) C++ Compiler in Android Studio* for how to use Intel C++ Compiler.

Required Software Tools

Successful installation of INDE 2015 Update 1 with Android Studio Integration will ensure you have the all required software installed.

Please refer to the latest Intel(R) C++ Compiler Release Notes for Intel(R) Integrated Native Developer Experience 2015 for detailed software and system requirements.

The instructions provided in this article uses the following software for targeting both IA-32 and Intel®-64 architecture:

  • Oracle* JDK 7 (native Intel-64 JDK for Windows x64 systems)
  • Android SDK 20 or greater
  • NDK r10d (assumed to be installed at: [ndk-dir] )
  • Android Studio 1.0.1

Please make sure the following Android NDK directories were added to the environment variable PATH (add them if missing):

  • C:\Intel\INDE\IDEintegration\NDK\build\tools
  • C:\Intel\INDE\IDEintegration\NDK

Using Intel(R) C++ Compiler in Android Studio* 1.0.1

After the Intel C++ Compiler 15.0 for Android is installed, the following toolchains are installed to "[ndk-dir]\toolchains" folder (the default directory is "C:\Intel\INDE\IDEintegration\android-ndk-r10d\toolchains"):

  • x86-icc
  • x86-icc15.0.X.YYY
  • x86_64-icc (if NDK supports 64-bit target)
  • x86_64-icc15.0.X.YYY (if NDK supports 64-bit target)

For NDK up to r9d: The default native C/C++ compiler will be the Intel C++ Compiler after the installation. There is no additional steps to use Intel C++ Compiler within Android Studio. If you would like to use GNU* gcc to build the native code, please follow Changing the default compiler back from Intel C++ Compiler to GCC for x86 targets.

For NDK r10 to r10d: The Intel C++ compiler is not default after the installation. Follow steps 3, 4, 5 below to use Intel C++ Compiler from Android Studio.

If you have multiple Android NDKs installed, please see instructions on this article Integrating the Intel(R) C++ Compiler for Android* with multiple Android NDKs.

We will now create a new Android project for Intel-64 with a native function call to demonstrate the use of Intel C++ Compiler:

  1. Create a new Android project with a native interface:

    1. Open Android Studio, Create a new Android project "nativeDemo" with default settings. e.g.

      Image 1

    2. Open "app\src\main\java\" and add a native function as below at the end of the class "MainActivity":
      public native String getStringFromNative();

      You file should now look like this:

      Image 2

    3. To build your "nativeDemo" project select: "Build > Make Project" to get ready for using "javah".
    4. Open the terminal window from "View > Tools Windows > Terminal" and follow the steps below to run "javah" and create the jni header:
      1. In the terminal window, navigate to the "src\main" subfolder:
        cd src\main
      2. Then, to create the "com_example_nativedemo_app_MainActivit.h" under the src\main\jni folder, run the following "javah" cmd:
        javah -d .\jni -classpath C:\Intel\INDE\IDEintegration\android-sdk-windows\platforms\android-21\android.jar;..\..\build\intermediates\classes\debug com.example.mydemo.nativedemo.MainActivity

      e.g.Image 3

    5. In the Project window change the view to Project and right click on the "src" folder and select "Synchronize 'src'". Now you can see the header file "com_example_mydemo_nativedemo_MainActivity.h" under the "src\main\jni" folder.
  2. Add native source code: main.c

    1. Create "main.c": select file " com_example_mydemo_nativedemo_MainActivity.h ", use copy/paste to create a new file "main.c" with following code:
      #include "com_example_mydemo_nativedemo_MainActivity.h"
        (JNIEnv * env, jobject obj)
          #ifdef __INTEL_COMPILER_UPDATE
              return (*env)->NewStringUTF(env, "Hello from Intel C++ !");
              return (*env)->NewStringUTF(env, "Hello from default C++ !");
    2. Save Changes
    3. Now you have 2 files under "jni" folder: com_example_mydemo_nativedemo_MainActivity.h and main.c

      Image 4

  3. Add make file:

    1. Right click on "jni" folder, select "New > File"
    2. Type "" and click "OK".
    3. Add the following lines to this file (note that LOCAL_SRC_FILES should contain source files located in "jni" folder:
      LOCAL_PATH := $(call my-dir)
      include $(CLEAR_VARS)
      LOCAL_MODULE    := nativeDemo 
      LOCAL_SRC_FILES := main.c 
      include $(BUILD_SHARED_LIBRARY)
  4. Add make file:

    1. Right click on "jni" folder, select "New > File"
    2. Type "" and click "OK".
    3. Add the following lines to this file:
      # For IA-32
      #include $(BUILD_SHARED_LIBRARY)
      # For Intel-64
      include $(BUILD_SHARED_LIBRARY)
    4. [Optional] to change compiler options, use the following:
      APP_CFLAGS := -O3
  5. Configure your application to run ndk-build with make files

    1. Open "app\build.gradle" file
    2. Add the following imports at the top of the file:
    3. Add the following lines after "defaultConfig" section:
      sourceSets.main {
          jniLibs.srcDir 'src/main/libs' //set .so files location to libs
      tasks.withType(NdkCompile) { // disable automatic ndk-build call
          compileTask -> compileTask.enabled = false
      task ndkBuild(type: Exec) { // call ndk-build(.cmd) script 
          if (Os.isFamily(Os.FAMILY_WINDOWS)) {
              commandLine 'cmd', '/c', 'ndk-build.cmd', '-C', file('src/main').absolutePath            
          } else {
              commandLine 'ndk-build', '-C', file('src/main').absolutePath
      tasks.withType(JavaCompile) {
          compileTask -> compileTask.dependsOn ndkBuild
    4. Add following line at end of the file:
      dependencies {
          compile fileTree(dir: 'libs', include: ['*.jar'])
    5. Save Changes
    6. Now build the project: select [Build > Make Project].You will see all the output folders and files "" under "main\libs" and "main\obj\local" folders.
  6. Add an ID "hello_textview" to the textview widget

    1. Open res\layout\activity_main.xml and modify the textview widget as shown below:
      	android:id="@+id/hello_textview" />
  7. ​Update "" to hook up the native library call to the UI textview widget:

    1. C++
      public class MainActivity extends Activity {
          static { // load the native library "nativeDemo"
          protected void onCreate(Bundle savedInstanceState) {
                  // get the text string from native API, and display on the UI
              TextView tv = (TextView)findViewById(;
    2. Press ALT + ENTER to import the TextView widget and save your changes.
  8. Start the Android Virtual Machine "Intel-Nexus 7 x64" and run the app by clicking the "Run" button.

    Image 5

    This means the compiler used is the Intel C++ Compiler for Android*.


Now you know how to build a simple native Android app with Intel C++ Compiler in Android Studio. Try it with your real native application and let us know how it goes.

This article applies to:
    Products: Intel® INDE Update 1 or later
    Host OS: Windows (IA-32, Intel® 64)
    Target OS: Android* (IA-32, Intel® 64)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
United States United States
Intel is inside more and more Android devices, and we have tools and resources to make your app development faster and easier.

Comments and Discussions

-- There are no messages in this forum --