6

I have developed an application and a native library for Android. The native library uses openSL ES for audio processing.

In my Android.mk file I have the following statement:

LOCAL_LDLIBS := -lOpenSLES

So I'm guessing that this means that the application will dynamically link in the openSLES library from the device's system/lib folder at the time when the application is loaded/executed on the device?

The problem I'm facing is that the libraries on the device are buggy and I have 3 updated libraries which contain the bug fix. If possible, how do I make sure that my native library is using the 3 libraries I have:

Libwilhelm.so
libOpenMAXAL.so
libOpenSLES.so

Do I just replace

LOCAL_LDLIBS := -lOpenSLES

with

LOCAL_SHARED_LIBRARIES := -lOpenSLES -lOpenMAXAL -lwilhelm
ArtKorchagin
  • 4,801
  • 13
  • 42
  • 58
user1884325
  • 2,530
  • 1
  • 30
  • 49

1 Answers1

4

As long as you target a specific device or a very limited set of devices, the proposed solution is good enough. But if your aim is a public app, which will be installed on different platforms, including future 'N' version of Android, and customized ROMs, including e.g. Samsung, you should be careful with the system dependencies of these libraries.

While OpenSLES and OpenMAXAL are innocent (they only depend on liblog and libwilhelm), the latter requires more care.

Looking at its Android.mk, libwilhelm depends on liblog libutils libmedia libbinder libstagefright libstagefright_foundation libcutils libgui libdl libeffects and libstagefright_http_support.

Only liblog and libdl are "official" (i.e., part of NDK). The others depend on platform, and their exported functions may be incompatible for different devices running same platform level.

To be on the safe side, I would only introduce the fixes, and keep using the system version of libwilhelm when possible. I hope you can reduce your system dependencies this way.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • So how exactly do I make sure that my app is using my version of libOpenSLES.so instead of the buggy version in system/libs? Specifically, what should my Android.mk file look like? – user1884325 Nov 24 '15 at 18:52
  • Yes, if you specify it in LOCAL_SHARED_LIBRARIES it will get installed on the device with your APK. On recent Android versions, it will be loaded automatically. On older versions, the loader may prefer to load libs from system directory, so there you can use explicit System.loadLibrary() or dlopen(). – Alex Cohn Nov 24 '15 at 20:52
  • When you say older we are talking about pre-4.4.2 ? And by "loaded automatically" you mean that my local shared lib will be loaded automatically? How do I verify where the lib is actually loaded from when the application is launched on a device? – user1884325 Nov 24 '15 at 21:01
  • Oh, you can see the logcat. And *older* - I don't remember exactly, but KitKat is definitely "on the good side". – Alex Cohn Nov 24 '15 at 21:36