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

OceanBlue picture OceanBlue · Apr 14, 2011 · Viewed 42k times · Source

I have used ndk successfully to build & 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 & paste the whole libs/armeabi/libcommon.so to the project root does not work, I think because libs/armeabi is an android generated path.

So what would be the best way to do it?

I am using Eclipse-Galileo & ndk5.

Answer

gnychis picture gnychis · Apr 20, 2011

There is a much simpler way to do all of this.

Let's say that your prebuilt library is called "libprebuilt.so"

In the project folder of the new project you want to only include the prebuilt library, do something like:

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

Then, just create a 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 in to libs/armeabi/ ... that's all!