NDK - How to use the generated .so library in another project

I have successfully used ndk to create and use a .so file in one project. I need to use this library in another project. I would rather not copy the source there, but just use the library. Trying to copy and paste the entire libs / armeabi / libcommon.so file to the project root does not work, I think because libs / armeabi is the path created by androids.

So what would be the best way to do this?

I am using Eclipse-Galileo and ndk5.

+43
android android-ndk
Apr 14 '11 at 20:24
source share
3 answers

I figured out how to do this, so post it here if anyone else comes across it.

  • The code for sharing (including the Java JNI shell, native code, .so-library) must be in a separate project. Convert this to a library project by right-clicking on the project name → properties → Android properties → check the "Library" checkbox. This project cannot be executed now, but other projects may link to it.

  • In the project that will use the shared object, add a link to the Libarray project by right-clicking on the project name → properties → Android properties → Library / Add. This should show the library project created in the previous step. Select it.

Now .so can be easily transferred between different projects.

+20
Apr 20 2018-11-18T00:
source share

There is a much simpler way to do all this.

Say your prebuilt library is called "libprebuilt.so"

In the project folder of the new project, you want to include only the previously created library, do the following:

mkdir -p jni/libprebuilt cp libprebuilt.so jni/libprebuilt 

Then just create the jni / libprebuilt / Android.mk file:

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libprebuilt LOCAL_SRC_FILES := libprebuilt.so include $(PREBUILT_SHARED_LIBRARY) 

Then, when you do ndk-build, it will copy this library to libs / armeabi / ..., that's all!

+44
Apr 20 '11 at 19:19
source share

JNI (Java Native Interface) function names have a package name (for example, JNIEXPORT void JNICALL Java_com_myapp_myclass_funct ). Therefore, I think you should rename these funkcions in the library in order to recompile it. Or perhaps use it as an external package in your application.

+7
Apr 14 2018-11-21T00:
source share



All Articles