# Android.mk
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := test.c
include $(BUILD_SHARED_LIBRARY)
# Native activity
main
include $(CLEAR_VARS)
LOCAL_MODULE := native-activity
LOCAL_SRC_FILES := main.c
LOCAL_LDLIBS := -llog -landroid
LOCAL_SHARED_LIBRARIES := test
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
The generated apk fails to load the libnative-activity.so,
with logcat output:
E/AndroidRuntime( 5038): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.example.luanative/
android.app.NativeActivity}: java.lang.IllegalArgumentException:
Unable to load native library: /data/data/com.example.luanative/lib/
libnative-activity.so
Everything works all right if test is built and linked as a
STATIC_LIBRARY.
I really don't want to link statically--my final application has a
number
of interlinked libraries which are quite large if all statically
linked against
each other. Surely, there must be a way to have a native activity use
a shared library...
On Dec 10, 5:49 pm, Tor Lillqvist <t...@iki.fi> wrote:
> This was discussed recently here. The Android dynamic linker is much
> simpler than the GNU/Linux one. I hope my reply in that thread will be
> useful:
>
> You need to handle loading of dependent shared libraries yourself, *before*
> a shared library that depends on them is loaded. For example code, see the
> lo_dlopen() function inhttp://cgit.freedesktop.org/libreoffice/core/tree/sal/android/lo-boot....
It looks like they are internally doing a RTLD_NOW dlopen
on the native activity .so, so if you have any calls to
a custom shared library, there is no opportunity for your
code to do a dlopen before everything crashes.