2

I'm writing a native lib (mylib.so) for Android, using the NDK. Mylib.so depends on libssl.so.

The Android NDK doc tells me I shouldn't use libssl.so from system/lib, because it's not part of the stable API. Instead I should cross-compile libssl myself and add it to the NDK.

But I see that mylib.so get automatically linked with system/lib/libssl.so because the dalvik vm (which is loading mylib.so) already depends on libssl.so.

$ readelf -d /system/bin/dalvikvm | grep Shared
 0x00000001 (NEEDED)                     Shared library: [libdvm.so]
 0x00000001 (NEEDED)                     Shared library: [libssl.so]
 0x00000001 (NEEDED)                     Shared library: [libz.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]
 0x00000001 (NEEDED)                     Shared library: [libstdc++.s
 0x00000001 (NEEDED)                     Shared library: [libm.so]

So what is the correct way to deal with this? Using system/lib/libssl.so anyway?

Thanks

user2194434
  • 71
  • 1
  • 4
  • Can you link libssl into `mylib.so` as a static library (`libssl.a`)? – fadden Mar 21 '13 at 21:33
  • I could probably link statically, but I'm not sure if that is a universal solution, e.g. in the case 2 libs in the same app both need libssl. To specify my question: is it safe to link dynamically with system/lib/libssl.so, knowing that it's not a stable API? Have other people tried this? Are there known pitfalls or functionality gaps when using system/lib/libssl.so? Thanks – user2194434 Apr 05 '13 at 13:41
  • 2
    It's never safe to link against non-public libraries. They can change when the system is updated, possibly breaking your app. Another idea would be to rename libssl.so to something else (libssl-mine.so) and link against that; that would prevent the dynamic linker from being "clever" and finding the system's implementation. – fadden Apr 05 '13 at 15:58
  • OK, but renaming the lib name doesn't solve the fact that I get duplicate symbols when loading mylib.so in a VM app, because Dalvik VM already links against the system libssl.so. Is there a way to force the dynamic linker to resolve symbols in mylib.so to libssl-mine.so? Thanks again – user2194434 Apr 08 '13 at 09:02

2 Answers2

1

You can download it on the following site: http://www.mediafire.com/download/njyqyxu3nxm/tcpdump.zip

user101207
  • 36
  • 5
0

It sounds like the problem might be in your Android.mk file. Assuming that you have already successfully cross-compiled the version of libssl you want into a .so file, you will want to make a new module in your Android.mk file that looks something like the following:

include $(CLEAR_VARS)
LOCAL_MODULE := libssl-prebuilt
LOCAL_SRC_FILES := libssl.so
LOCAL_EXPORT_C_INCLUDES := /path/to/the/include/files/for/libssl.so
include $(PREBUILT_SHARED_LIBRARY)

The above module adds your local pre-built version of libssl.so to your native project. If, when compiling mylib.so, you want to link in your local version of libssl.so, you must add the following entry to your mylib module.

LOCAL_SHARED_LIBRARIES := libssl-prebuilt