How to link a prebuilt shared Library to an Android NDK project?

Here is a complete Android.mk file for using a 3rd party shared library.
The library (libffmpeg.so) is placed in the jni folder.
Its “LOCAL_EXPORT_C_INCLUDES” specifies where the header files are kept for the library.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg
LOCAL_SRC_FILES := libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../ffmpeg/libs/arm-linux-androideabi4.7_1/include
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE    := ffmpegandroid
LOCAL_SRC_FILES := ffmpegandroid.c
LOCAL_SHARED_LIBRARIES := ffmpeg
include $(BUILD_SHARED_LIBRARY)

If you wanted to support multiple architectures then you could specify:

APP_ABI := armeabi armeabi-v7a x86 mips

in your jni/Application.mk and change the LOCAL_SRC_FILES to something like:

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libffmpeg.so

and place a libffmpeg.so at jni/armeabi/libffmpeg.so, jni/armeabi-v7a/libffmpeg.so etc ..

Leave a Comment