Here is a nice tutorial that I followed as the basic step : http://mobile.tutsplus.com/tutorials/android/ndk-tutorial/

Some notes about NDK:

  • Use it if your code is processor bound
  • If you have already c / c++ code that you want to use in your project, you don’t need to rewrite them in Java. Just use NDK.
  • JNI: Java Native Interface. It defines a way for managed code to interact with native (c/c++) code.
  • JNIEnv and JavaVM are pointers to pointers to function tables.
  • Android allows only one JavaVM to be active at the same time.
  • Native Functions receive JNIEnv as the first argument.
  • You cannot share JNIEnv between threads. If needed, share JavaVM and use GetEnv.
  • c and c++ definitions are different. Beware!
  • Debugger is only available for Android 2.2 and newer platforms.

Step-by-step

  1. write native code (c/c++)
  2. add to jni folder of your project ( if there is no folder named jni, create it)
  3. call the native code from the java code. load the library.
  4. create makefile: Android.mk
  5. ndk-build from terminal
  6. refresh project and run
Advertisements