I have a project organized as follow:
project/jni/Android.mk
project/jni/libA/Android.mk
project/jni/libB/Android.mk
project/lib/armeabi/libA.so
project/lib/arme
As the name suggests, the prebuilt libraries will never be built (they are already built). If you need to build the prebuilt libraries again, you will need to include their sources and change you Android.mk to use those sources to build those modules again, using BUILD_SHARED_LIBRARY. However, you can include the whole library source tree into a libs
folder and include it's Android.mk into yours.
Please note that the libraries that you add in are only built if their source changes and don't get affected by other modules changing.
A basic example is as below:
First the layout of the project. There are 3 modules:
File Layout:
sdk@AndroidDev:~/ndk/sources/getver$ find jni/
jni/
jni/getver.c
jni/libs
jni/libs/libver
jni/libs/libver/compiled_ver.c
jni/libs/libver/Android.mk
jni/libs/libver/ver.h
jni/libs/libmagic.so
jni/libs/Android.mk
jni/Android.mk
Next, the toplevel Android.mk (it's in jni/):
sdk@AndroidDev:~/ndk/sources/getver$ cat jni/Android.mk
LOCAL_PATH := $(call my-dir)
my_LOCAL_PATH := $(LOCAL_PATH)
# Include all libs (built and prebuilt)
include $(LOCAL_PATH)/libs/Android.mk
# Build my executable
LOCAL_PATH := $(my_LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := getver
LOCAL_SRC_FILES := getver.c
LOCAL_SHARED_LIBRARIES= ver magic
include $(BUILD_EXECUTABLE)
The jni/libs/Android.mk, for including all libs:
sdk@AndroidDev:~/ndk/sources/getver$ cat jni/libs/Android.mk
LOCAL_PATH := $(call my-dir)
# Prebuilt Lib
include $(CLEAR_VARS)
LOCAL_MODULE := magic
LOCAL_SRC_FILES := libmagic.so
include $(PREBUILT_SHARED_LIBRARY)
# Lib to be built as part of building process.
include $(CLEAR_VARS)
include $(LOCAL_PATH)/libver/Android.mk
Finally, Android.mk of libver.so (jni/libs/libver/Android.mk):
sdk@AndroidDev:~/ndk/sources/getver$ cat jni/libs/libver/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ver
LOCAL_HDR_FILES := ver.h
LOCAL_SRC_FILES := compiled_ver.c
include $(BUILD_SHARED_LIBRARY)
In the above example, the libmagic.so is never going to be built, as it is a prebuilt lib. However, libver.so will be built everytime libver sources change. It will not be rebuilt if getver sources change. Illustrated example below(I use touch command to simulate change in getver.c source):
First time build:
sdk@AndroidDev:~/ndk/sources/getver$ ../../ndk-build
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile thumb : getver <= getver.c
Compile thumb : ver <= compiled_ver.c
SharedLibrary : libver.so
Executable : getver
Install : getver => libs/armeabi/getver
Prebuilt : libmagic.so <= jni/libs/
Install : libmagic.so => libs/armeabi/libmagic.so
Install : libver.so => libs/armeabi/libver.so
Simulate editing of getver module sources:
sdk@AndroidDev:~/ndk/sources/getver$ touch jni/getver.c
Rebuild(notice libver.so is NOT rebuilt):
sdk@AndroidDev:~/ndk/sources/getver$ ../../ndk-build
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile thumb : getver <= getver.c
Executable : getver
Install : getver => libs/armeabi/getver
Install : libmagic.so => libs/armeabi/libmagic.so
Install : libver.so => libs/armeabi/libver.so
Simulate editing of libver.so sources
sdk@AndroidDev:~/ndk/sources/getver$ touch jni/libs/libver/compiled_ver.c
Rebuild(notice getver is rebuilt as it depends on libver.so:
sdk@AndroidDev:~/ndk/sources/getver$ ../../ndk-build
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile thumb : ver <= compiled_ver.c
SharedLibrary : libver.so
Executable : getver
Install : getver => libs/armeabi/getver
Install : libmagic.so => libs/armeabi/libmagic.so
Install : libver.so => libs/armeabi/libver.so
You can have the following in higher-level Android.mk files to recursively go through the directories. You'd put it in project/jni/Android.mk and it'd go into libA and libB and process the Android.mk files in them.
include $(call all-subdir-makefiles)