gpt4 book ai didi

android - 如何在 Android Nougat 中替换 dlopen()?

转载 作者:搜寻专家 更新时间:2023-11-01 08:29:37 26 4
gpt4 key购买 nike

我有一个 NDK 应用程序,可以通过 dlopen 加载的插件进行扩展。这曾经工作得很好,但它不再适用于 Android N。如 developer documentation 中所述, dlopen 现已正式废弃:

Starting in Android 7.0, the system prevents apps from dynamically linking against non-NDK libraries, which may cause your app to crash. This change in behavior aims to create a consistent app experience across platform updates and different devices.
...
All apps generate a runtime error when they call an API that is neither public nor temporarily accessible. The result is that System.loadLibrary and dlopen(3) both return NULL, and may cause your app to crash.

我看到有一个 hack简单地为 Android 手动实现 dlopendlsym。这似乎适用于 Android N,但当然没有人知道它还能工作多久。

这就是为什么我正在考虑将我的插件设计更改为官方支持且面向 future 的东西。最明显的选择是使用 Android 的服务 API,并将我的插件简单地分发为实现服务的单独 APK。

但是,我不太喜欢这个想法,因为我使用的是 NDK,而且我认为服务 API 不适用于 NDK。当然,我可以用 Java 创建一个服务,然后使用 JNI 将它与我的 C 代码集成,但这当然不是一个非常优雅的解决方案。

这就是为什么我想问一下,在 Android N 中支持以前基于 dlopen 的插件的推荐方法是什么?是否有替代路线,或者我现在是否被迫使用服务 API?

最佳答案

备案;这在 android-ndk 谷歌组/邮件列表中进行了讨论,事实证明 dlopen 根本不是原始海报的罪魁祸首:

https://groups.google.com/d/msg/android-ndk/hhUv1mg3c_A/a5BbRtr-AwAJ

Oops, sorry, actually, dlopen() is still working fine on Android 7.0. I was getting the following error message:

Detected problems with app native libraries (please consult log for detail): 
foobar.so: text relocations

进一步阐明了开发者文档中的措辞:

https://groups.google.com/d/msg/android-ndk/hhUv1mg3c_A/eIKHZZcDBAAJ

I guess the wording does technically make it sound like you're now [sic: read not] allowed to link to your own libraries. That definitely is not the case. The policy is that your cannot link to or dlopen private system libraries (anything in /system/lib that is not in the NDK).

关于android - 如何在 Android Nougat 中替换 dlopen()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41897797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com