By Jennifer L Jiang,
Published:03/27/2014 Last Updated:10/15/2014
Table of Content:
For using Intel C++ Compiler in Android Studio 1.0.1, please refer to this other article Building Native Android* Apps Using Intel(R) C++ Compiler in Android Studio* 1.0.1.
The article applies to Android Studio* beta 0.8.6. The Intel® C++ Compiler for Android as part of Intel® Integrated Native Developer Experience (Intel® INDE) is supporting Android Studio as preview feature in Intel INDE 2015 RTM release. There is no additional change or work necessary providing that your native application can be built within Android Studio.
The Intel® C++ Compiler for Android (ICC) is configured as default compiler for x86 targets in the NDK build system during installation. Android Studio is using Gradle as build system. As time of writing Gradle invokes the NDK build system as part of the build process. Therefore ICC is also the default compiler for x86 targets in Android Studio. There is no additional configuration or setup in Android Studio required.
The steps below are describing in general how to setup a new native application in Android Studio, build and run it.
To develop native apps in Android Studio, the following tools are required:
After the Intel C++ Compiler 15.0 for Android installed, the following toolchains are installed to "[ndk-dir]\toolchains" folder:
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.
Due to beta status of Android Studio you may experience some issues while importing samples from NDK directly. We will create a new Android project with a native function call to demonstrate the use of Intel C++ Compiler.
public native String getStringFromNative();
#include "com_example_nativedemo_app_MainActivity.h"
JNIEXPORT jstring JNICALL Java_com_example_nativedemo_app_MainActivity_getStringFromNative
(JNIEnv * env, jobject obj)
{
#ifdef __INTEL_COMPILER_UPDATE
return (*env)->NewStringUTF(env, "Hello from Intel C++ !");
#else
return (*env)->NewStringUTF(env, "Hello from default C++ !");
#endif
}
defaultConfig {
minSdkVersion 18
targetSdkVersion 19
versionCode 1
versionName "1.0"
ndk {
moduleName "myNativeTest"
abiFilter "x86"
}
}
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hello_textview" />
public class MainActivity extends Activity {
static { // load the native library "myNativeTest"
System.loadLibrary("myNativeTest");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get the text string from native API, and display on the UI
TextView tv = (TextView)findViewById(R.id.hello_textview);
tv.setText(this.getStringFromNative());
}
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 2015 RTM
Host OS: Windows (IA-32, Intel® 64)
Target OS: Android*
Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.