In a recently posted stable release of Intel Threading Building Blocks (Intel® TBB), we have added experimental support for Android applications; i.e., building Intel TBB libraries for use in Android applications via the JNI interface. You can download this release from threadingbuildingblocks.org.

To start the process on a Linux* host, unpack the Intel TBB source distribution, source the <unpacked_dir>/build/android_setup.csh script, and build the libraries. Building the libraries is necessary because development releases are distributed in source form only. The <unpacked_dir>/build/index.android.html file contains instructions to configure the environment and build the library on Linux.

Assuming that gnu make 3.81 is available in the %PATH% (on a Microsoft Windows* host platform) and $PATH (on a Linux host) we need to issue the following command in the NDK environment to build the Intel TBB libraries for Android:

gmake tbb tbbmalloc target=android

That’s all that is needed for the library build; we can now move to build the example using Eclipse*. For the example below, I’ll use Android SDK Tools Rev.21 and Android NDK Rev 8C on Windows* to illustrate the process of cross-platform development.

Create a new project using a default template «New Android Application». For simplicity, we name it “app1”, the same as in the previous post:

Select FullscreenActivity as the Activity. That’s it for the template. Please note that com.example* is not an acceptable package naming for Google Play* but it is good enough for our example.

Then add a couple of buttons to the main frame. After adding these, the XML file of the main frame (app1/res/layout/activity_fullscreen.xml) will look like this:

In the case of the "tbb" library everything should be clear, and the "gnustl_shared" library is required to support the C++ language features of TBB. However, for the "jni-engine" library we need to go into more details.

"jni-engine" is a С++ library that implements a calculation engine and exports C-interfaces for JNI calls named onClickSRCall() and onClickSRCall().

According to NDK development rules, create folder “jni” inside the workspace and create 3 files there specific for our "jni-engine" library.

These files are:

Android.mk (text in <> brackets there is something that should be replaced with actual values)

When we use the NDK to build, it compiles libraries to the required folders including our libraries libjni-engine.so, libgnustl_shared.so and libtbb.so.

Next, switch back to Eclipse and build the app1.apk file. Now the application is ready to install on AVD or actual hardware. On AVD it looks like

That’s it! This simple application is ready and should be a good start towards writing a more complex parallel application for Android. And for those who used code from the previous blog, the application was successfully ported to Android.