Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NDK: C++ runtime restrictions when using prebuilt shared libraries

I have a project that uses gnustl_static as the c++ runtime, which is globally set in Application.mk.

In the project, I'd like to include now a prebuilt shared library from a 3rd party that implements some functionality. For this I use the PREBUILT_SHARED_LIBRARY mechanism that the NDK build system provides:

include $(CLEAR_VARS)
LOCAL_MODULE := xyzAPI
LOCAL_SRC_FILES := libxyz-api.so
include $(PREBUILT_SHARED_LIBRARY)

and then later to use it in the main Android.mk

LOCAL_SHARED_LIBRARIES += xyzAPI

From the 3rd party I know that libxyz-api.so has been created using the c++_shared runtime.

Question 1: Do I need to care about the fact that my dependency library has been built with a different runtime? If yes, does it mean that I'd have to move my entire project to c++_shared?

Question 2: Since dependency xyzAPI has been built with the c++_shared runtime do I now have to load up c++_shared on the Java side of things (i.e. System.loadLibrary("c++_shared");)?

like image 669
rsp1984 Avatar asked Aug 08 '26 21:08

rsp1984


1 Answers

  1. This is definitely a valid concern. Using different c++ runtimes within a project is not impossible, but tricky and dangerous.

  2. Since jb-mr2 (API level 18) the system will do it for you (see https://code.google.com/p/android/issues/detail?id=34416). But it's your responsibility to have the relevant .so file packaged in your APK, including all relevant ABI variations.

In summary, I believe that switching to c++_shared is easier than to watch for all possible failures.

like image 120
Alex Cohn Avatar answered Aug 11 '26 11:08

Alex Cohn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!