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

前端 未结 2 824
谎友^
谎友^ 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:34

    PREBUILT_SHARED_LIBRARY Points to a build script used to specify a prebuilt shared library. Unlike BUILD_SHARED_LIBRARY and BUILD_STATIC_LIBRARY, the value of LOCAL_SRC_FILES must be a single path to a prebuilt shared library (e.g. foo/libfoo.so), instead of a source file.

    You can reference the prebuilt library in another module using the LOCAL_PREBUILTS variable (see docs/PREBUILTS.html for more information).

       LOCAL_PATH := $(call my-dir)
    
       include $(CLEAR_VARS)
       LOCAL_MODULE := foo-prebuilt
       LOCAL_SRC_FILES := libfoo.so
       include $(PREBUILT_SHARED_LIBRARY)
    

    Refrenced from NDK documentation.

    PREBUILT_STATIC_LIBRARY This is the same as PREBUILT_SHARED_LIBRARY, but for a static library file instead. See docs/PREBUILTS.html for more.

    Please read the NDK documentation for more details.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题