Building a C ++ static library for use with Java on Android

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

+2


a source to share


2 answers


Use Android NDK



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

+1


a source


You can scroll down the Google NDK page to get some information. You can also check OVERVIEW.TXT in the NDK folder after downloading it to see how to get started.

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



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

      

When you create a Java application, it must make its way into your own library code when you call your own functions.

+1


a source







All Articles