Building a native Android* app with Intel® C++ Compiler in Android Studio*

Introduction

This article provides the steps on how to build a native Android* app using Android NDK and Intel(R) C++ Compiler for Android in Android Studio* 3.0. The current Android Studio* release is 3.0.1 at the time of this writing.

The workflow was changed in comparison to Android Studio 2.3. Now it is possible to use Gradle features such as "externalNativeBuild” to build the native module with Intel(R) C++ Compiler. The instruction was much simplified in Android Studio 3.0.

Required Software Tools

  • Android Studio 3.0
  • Android Gradle Plug-in 3.0
  • Gradle 4.1
  • Android SDK Build Tool 26.0.2 or later
  • Android NDK r15c or later  (assumed to be installed at: [ndk-dir] )
  • Successful installation of Intel System Studio 2018 with Intel C++ Compiler integrated into Android NDK

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

We will use a sample from Android NDK samples to demonstrate the use of Intel C++ Compiler with Android Studio* 3.0.

Download samples from https://github.com/googlesamples/android-ndk/tree/master-ndkbuild and extract them.

Open Android Studio, click File > New > Open Project. Navigate to Android NDK samples location and select hello-jni sample.

If you see “Android Gradle Plugin Update Recommended” message, please update it.

If you see the error below, please click “Update Build Tools version and sync project”

Open local.properties file. It should contain path to Android NDK. Set up “ndk.dir” variable with path to Android NDK with integrated Intel® C++ compiler:

ndk.dir=C\:\\Android\\Sdk\\ndk-bundle

Configuring your application to run ndk-build with Intel(R) C++ compiler

Open "app\build.gradle" file:

Add the following lines inside defaultConfig section.

externalNativeBuild {
    ndkBuild {
        abiFilters 'x86_64'
        arguments "V=1 NDK_TOOLCHAIN:=x86_64-icc"
    }
}

Save Changes.

Now build the project: select [Build > Make Project]. The lib "libhello-jni.so" will be generated inside hello-jni\app\build\intermediates\ndkBuild\debug\obj\local\x86_64 and get included inside your APK.

If you want to build your application for x86 target, change ndk abifilters to x86:

externalNativeBuild {
    ndkBuild {
        abiFilters 'x86'
        arguments "V=1 NDK_TOOLCHAIN:=x86-icc"
    }
}

Summary

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.

 

 


For more complete information about compiler optimizations, see our Optimization Notice.