Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link to the libmedia.so system library in an Android NDK app using android.mk?

I want to create a Player which uses Android system/lib/libmedia.so.

Directly use JNI to play a video.

In Android.mk, i add "-lmedia" for including the library, but i can't link this directly.

This is my process.

  1. write a Cpp file which includes some header file in libmedia.so

  2. add "-lmedia" in Android.mk of LOCAL_LDLIBS

    such as..

    LOCAL_LDLIBS -lmedia -lstagefright

  3. use ndk-build to build .so

error occured!!

Does anybody have some answer to help???

like image 292
OneGuilty Avatar asked Oct 29 '12 04:10

OneGuilty


1 Answers

libmedia.so and libsinstructionght.so are not part of the public API. This means that in theory, you should not rely on them. In practice, though, these libraries are present on all devices, but they are different.

You can extract this binary file from your device, or even from an emulator using command

adb pull /system/lib/libmedia.so C:/android-ndk/platforms/android-14/arch-arm/usr/lib

This will put ths file together with the public API so that using it with ndk-build is easier. On the other hand, you should be aware of fragmentation not lnly between different levels of Android, but also chipsets, manufacturers, and even models.

To handle this, I pull .so files from different devices into separate directories, and add one of them to the linker path, e.g.

LOCAL_LDLIBS += -Lc:/android/galaxys.4.1.2.system.lib

This instruction above can not resolve the big problem you are facing with your approach. libmedia.so is not intended to be linked to user apps. It assumes the context of a privileged user with access to protected devices, such as camera, codecs, and screen.

You can make full use of this library if you target a rooted device, or prepare a custom ROM. And know what you are doing, and how to avoid stealing essential resources from the system.

Otherwise there is very little gain in linking the media lib.

like image 73
Alex Cohn Avatar answered Sep 21 '22 14:09

Alex Cohn