Google’s Android NDK is a great toolset for developers who need to integrate C/C++ code with their Android apps. The NDK uses the Java Native Interface (JNI) to provide a bridge between Java and native C/C++ code, while also providing many common C libraries and APIs to build upon. On top of this, the NDK also guarantees forward ABI compatibility with various versions of the ARM instruction set, meaning your native code will run on any Android device that implements the instruction set that your app is built against. The NDK is in fact the preferred way that games (using OpenGL) and other high-performance or hardware level code should be implemented. The latest NDK r5 even ships with support for Native Activities, Sensors, Windows, Surfaces, Event Loops, OpenSL Audio, STL, and more.
Here’s a brief outline of the new NDK support for Titanium Android modules/apps:
- Modules have 2 new properties that are supported in the top level “build.properties” file. These properties enable automatic ndk-build when “ant” is used to build the module:
- Under the “jni” folder of your module project, place your C/C++ source and Android.mk file
- Native libraries (.so) are automatically included in the zip of your Android module under “dist”, and any Titanium app that uses your module will automatically import the native library correctly into the final APK
DISCLAIMER: Our NDK support will still be beta for our upcoming 1.6 release, we hope to finalize it for 1.7.
What follows is a quick video that shows how I integrated some simple C code into a Titanium Android module, and used it inside a Titanium app: