Possible to Override system .so library in App

android, android-mediaplayer, android-ndk, stagefright

Solution

You will not be able to replace the original library, since when you try to `loadLibrary` it will load the library from within `/system/lib`. So unless you replace that (which is not possible on unrooted devices), you won't be able to load your custom code.

https://github.com/android/platform_system_core/blob/66ed50af6870210ce013a5588a688434a5d48ee9/rootdir/init.environ.rc.in sets the `LD_LIBRARY_PATH` by default. And loads it from these paths if available. If not, then your application's `lib` directory will be searched; but not the other way around.

I tried this with `libwebkit.so` in the past on various mainstream devices and haven't had any luck getting it to load instead of the one in `/system/lib`.

You can learn more by looking at:

- `doLoad` from here https://android.googlesource.com/platform/libcore/+/41d00b744b7772f9302fdb94dddadb165b951220/luni/src/main/java/java/lang/Runtime.java

- `findLibrary` here http://developer.android.com/reference/dalvik/system/BaseDexClassLoader.html#findLibrary(java.lang.String)

I'm pretty sure you can't replace the default class loader either for security reasons.

What you can do, though, is a straightforward fork the Media Player and have it load your modified `libstagefright-modified.so`. There could be other solutions, haven't looked at Media Player's code.

Problem

I have to modify the Http Live Streaming implementation of Android Media Player. The implementation is under the stagefright library http://androidxref.com/4.0.4/xref/frameworks/base/media/libstagefright/httplive/LiveDataSource.cpp I think these library will compile to a libstagefright.so which should be part of the Android system. My question is if I make some changes to this library and compile a new libstagefright.so. If I load this new libstagefright.so in my new application and call up the media player, will it use the code in my new libstagefright.so?

Original source

Related problems