[Android] Building the JNI Source Code in Eclipse

When we develop a project includes the JNI technique, we should use the Android NDK tool for building these source code. But, the NDK is a command line tool that not convenient to use when we develop in the IDE.

In this article, I shows an example to explain the steps to build JNI source code in Eclipse.

The key is you have to create a new Builder used to execute the NDK tool for building JNI source code. So, at first, you have to create a new Builder in the Eclipse.

In my example, I try to add a new NDK Builder for OpenCV project in the Eclipse.

Step 1: Enter to the Project’s property window, and then click the “New” button to create a new Builder.

 

Step 2: Because we want to insert our own building tool, so we select the “Program” item.

Step 3: We should give a Builder name, NDK path, Project path.

Step 4: Set the refresh resources. In this step, you should select the “libs” folder for refreshing when building completion.


Step 5: Change to the “Build Options” label. Specify the resource to be compiled. You have to select the “jni” folder that contains the JNI source code.

Step 6: When you complete these configurations, the project will start the building procedure. Then, you can found out the libraries in the “libs” folder.

4 comments

  1. Hi,
    I'm working with the source code of VLC for Android and this includes JNI source code.

    I'm working with Juno Eclipse and I want to compile class libvlcjni.c when I edit it, I used the ndk-r8c order to build a "New builder" following his guidelines.

    When I modife the class libvlcjni.c, I get the following messages in console:

    / home/vmg/android/android-ndk-r8c/build/core/add-application.mk: 128: Android NDK: WARNING: APP_PLATFORM android-9 is larger than android: minSdkVersion 7 in. / AndroidManifest.xml

    Gdbserver: [arm-linux-4.6-androideabi] libs / armeabi / gdbserver

    Gdbsetup: libs / armeabi / gdb.setup

    make: * No rule to make target jni / .. / / modules / codec / omxil / iomx.cpp ', needed by obj / local / armeabi / objs-debug / iomx-gingerbread / __ / / modules / codec / omxil / iomx.o '. Stop.

    What am I doing wrong? Help, please.

  2. It seems like the incorrect SDK version. You should what's the platforms you are installed in the SDK. Or, you can modify the minSdkVersion in the AndroidManifest.xml to match the supporting in the SDK.

  3. Hi Picker,

    That is a very cool approach, I like it and want to make it work while keeping my OS… Windows. I know Windows has many issues(Require a bunch of other tools) with building JNI, but I was hoping perhaps you have some thoughts.

    Currently this approach fails because the ndk-build is not a windows command, How should I proceed?

    Adam.

發佈留言