如何使用 android.mk 链接到 Android NDK 应用程序中的 libmedia.so 系统库? [英] How to link to the libmedia.so system library in an Android NDK app using android.mk?

查看:14
本文介绍了如何使用 android.mk 链接到 Android NDK 应用程序中的 libmedia.so 系统库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个使用 Android system/lib/libmedia.so 的播放器.

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

直接使用JNI播放视频.

Directly use JNI to play a video.

在 Android.mk 中,我添加了-lmedia"以包含库,但我无法直接链接.

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

这是我的过程.

  1. 在 libmedia.so 中编写一个包含一些头文件的 Cpp 文件

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

在 LOCAL_LDLIBS 的 Android.mk 中添加-lmedia"

add "-lmedia" in Android.mk of LOCAL_LDLIBS

比如..

LOCAL_LDLIBS -lmedia -lstagefright

LOCAL_LDLIBS -lmedia -lstagefright

使用ndk-build构建.so

use ndk-build to build .so

发生错误!!

有人有答案吗???

推荐答案

libmedia.solibsinstructionght.so 不是公共 API 的一部分.这意味着理论上,您不应该依赖它们.但实际上,这些库存在于所有设备上,但它们是不同的.

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

这会将文件与公共 API 放在一起,以便更轻松地与 ndk-build 一起使用.另一方面,您不仅应该注意不同级别的 Android 之间的碎片化,还应该注意芯片组、制造商甚至型号之间的碎片化.

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.

为了处理这个问题,我将 .so 文件从不同的设备拉到单独的目录中,并将其中一个 添加到链接器路径中,例如

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

<小时>

上述说明无法解决您在方法中面临的大问题.libmedia.so 不打算链接到用户应用程序.它假定具有访问受保护设备(例如相机、编解码器和屏幕)的特权用户的上下文.


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.

如果您以 root 设备为目标,或准备自定义 ROM,则可以充分利用此库.并知道您在做什么,以及如何避免从系统中窃取重要资源.

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.

这篇关于如何使用 android.mk 链接到 Android NDK 应用程序中的 libmedia.so 系统库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆