Tutorial :Creating a C++ static lib to use with Java on Android



Question:

I have some C++ code that I want to make into a static lib for use with Java on the Android platform. Can anyone point me to a resource that tells me how to do this? I am completely new to Java and Android.


Solution:1

Use The Android NDK

They have a sample
$ make APP=hello-jni â€" compiles hello-jni.c and outputs a shared library to /apps/hello-jni/project/libs/armeabi/libhello-jni.so


Solution:2

You can scroll down on Google's NDK page to get some information. You can also check the OVERVIEW.TXT in the NDK folder once you've downloaded it to see how to get started.

Generally speaking, you need to build your shared library using the NDK, then import the shared library (e.g. libExample.so) into a Java Android project. The native functions need to be declared in the Java project using the 'native' keyword. You need to explicitly load your library by adding (following my example):

static  {      System.loadLibrary("Example");  }  

When you build the Java app it should punch through to your native library code when your native functions are called.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »