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

前端 未结 2 829
谎友^
谎友^ 2020-12-05 22:09

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 lib

2条回答
  •  臣服心动
    2020-12-05 22:45

    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.

提交回复
热议问题