When compiling several static libraries into one shared using Android NDK I ran into a problem and fixing it required changing the NDK.
Here is what the problem is. Let say I use this Android.mk:
LOCAL_PATH:= $(call my-dir)
LOCAL_MODULE := mod1
LOCAL_SRC_FILES := libmod1.a
LOCAL_MODULE := mod2
LOCAL_SRC_FILES := libmod2.a
#...more prebuilt static libs here...
LOCAL_MODULE := main
LOCAL_SRC_FILES := main.cpp
LOCAL_WHOLE_STATIC_LIBRARIES := mod1 mod2 <...>
This won’t work in NDK 5 and 5b, specifically the macro LOCAL_WHOLE_STATIC_LIBRARIES won’t do anything.
This is how to fix it:
locate the setup.mk file you use, it’s one of those:
find -name setup.mk
In my case it was “./toolchains/arm-linux-androideabi-4.4.3/setup.mk”.
In that setup.mk locate defines cmd-build-shared-library and cmd-build-executable.
In these defines look at the call with $(PRIVATE_WHOLE_STATIC_LIBRARIES) as a parameter:
make sure that “link-whole-archives” matches the one in build/core/definitions/mk.
In my toolchain I had “whole-link-archives-tags” instead of “link-whole-archives”.
Happy Android hacking!