Android7.0后JNI库禁止访问私有API

Google官网对于此修改的说明如下:

Private API (Enforced since API 24)

Native libraries must use only public API, and must not link against non-NDK platform libraries. Starting with API 24 this rule is enforced and applications are no longer able to load non-NDK platform libraries. The rule is enforced by the dynamic linker, so non-public libraries are not accessible regardless of the way code tries to load them: System.loadLibrary(...), DT_NEEDED entries, and direct calls to dlopen(...) will fail in exactly the same way.

Users should have a consistent app experience across updates, and developers shouldn’t have to make emergency app updates to handle platform changes. For that reason, we recommend against using private C/C++ symbols. Private symbols aren’t tested as part of the Compatibility Test Suite (CTS) that all Android devices must pass. They may not exist, or they may behave differently. This makes apps that use them more likely to fail on specific devices, or on future releases --- as many developers found when Android 6.0 Marshmallow switched from OpenSSL to BoringSSL.

In order to reduce the user impact of this transition, we’ve identified a set of libraries that see significant use from Google Play’s most-installed apps, and that are feasible for us to support in the short term (including libandroid_runtime.so, libcutils.so, libcrypto.so, and libssl.so). In order to give you more time to transition, we will temporarily support these libraries; so if you see a warning that means your code will not work in a future release -- please fix it now!

$ readelf --dynamic libBroken.so | grep NEEDED
 0x00000001 (NEEDED)                     Shared library: [libnativehelper.so]
 0x00000001 (NEEDED)                     Shared library: [libutils.so]
 0x00000001 (NEEDED)                     Shared library: [libstagefright_foundation.so]
 0x00000001 (NEEDED)                     Shared library: [libmedia_jni.so]
 0x00000001 (NEEDED)                     Shared library: [liblog.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x00000001 (NEEDED)                     Shared library: [libz.so]
 0x00000001 (NEEDED)                     Shared library: [libstdc++.so]
 0x00000001 (NEEDED)                     Shared library: [libm.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]

Potential problems: starting from API 24 the dynamic linker will not load private libraries, preventing the application from loading.

Resolution: rewrite your native code to rely only on public API. As a short term workaround, platform libraries without complex dependencies (libcutils.so) can be copied to the project. As a long term solution the relevant code must be copied to the project tree. SSL/Media/JNI internal/binder APIs should not be accessed from the native code. When necessary, native code should call appropriate public Java API methods.

A complete list of public libraries is available within the NDK, under platforms/android-API/usr/lib.

Note: SSL/crypto is a special case, applications must NOT use platform libcrypto and libssl libraries directly, even on older platforms. All applications should use GMS Security Provider to ensure they are protected from known vulnerabilities.

时间: 2024-10-12 10:58:30

Android7.0后JNI库禁止访问私有API的相关文章

关于Apple的私有API

介绍 一.基本知识 iPhone中的API除了公开的 API:Published API外(或者叫文档中记录的API:Documented API),还有两类API:私有API:Private API和未公开的API:UnPublished API(或者叫文档中未记录的API:Undocumented API).其中私有API是指放在PrivateFrameworks框架中的API,未公开的API是指虽然放在Frameworks框架中,但是却没有在苹果的官方文档中有使用说明.代码介绍等记录的AP

iPhone私有API

一.基本知识 iPhone中的API除了公开的API:Published API外(或者叫文档中记录的API:Documented API),还有两类API:私有API:Private API和未公开的API:UnPublished API(或者叫文档中未记录的API:Undocumented API).其中私有API是指放在PrivateFrameworks框架中的API,未公开的API是指虽然放在Frameworks框架中,但是却没有在苹果的官方文档中有使用说明.代码介绍等记录的API.后两

iOS私有API 以及api与sdk的解释

IOS的API分为四种: Published API(公开的API)(或者Documented API) 还有两类:私有API:Private API和未公开API:UnPublished API(或者Undocumented API). 私有API是指放在PrivateFrameworks框架中的API,未公开的API是指虽然放在Frameworks框架中,但是却没有在苹果的官方文档中有使用说明.代码介绍等记录的API. 按苹果的说法,未公开的API是还不够成熟,可能还会变动的API,等完全成

iOS私有API

IOS的API分为四种: Published API(公开的API)(或者Documented API) 还有两类:私有API:Private API和未公开API:UnPublished API(或者Undocumented API). 私有API是指放在PrivateFrameworks框架中的API,未公开的API是指虽然放在Frameworks框架中,但是却没有在苹果的官方文档中有使用说明.代码介绍等记录的API. 按苹果的说法,未公开的API是还不够成熟,可能还会变动的API,等完全成

VC6.0中友元函数无法访问类私有成员的解决办法

举个例子: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #include<iostream> using namespace std; class cylinder {     friend istream operator>>(istream& is,cylinder &cy); public:         inline doub

Android7.0 之 行为变更

我只是Google的搬运工...... 行为变更 本文内容 性能提升 低电耗模式 后台优化 权限更改 应用间共享文件 无障碍改进 屏幕缩放 设置向导中的视觉设置 NDK 应用链接至平台库 Android for Work 注解保留 其他重要说明 另请参阅 Android N API 概览 Android N 除了提供诸多新特性和功能外,还对系统和 API 行为做出了各种变更. 本文重点介绍您应该了解并在开发应用时加以考虑的一些重要变更. 如果您之前发布过 Android 应用,请注意您的应用可能

Android7.0 API变更

Android N 除了提供诸多新特性和功能外,还对系统和 API 行为做出了各种变更. 本文重点介绍您应该了解并在开发应用时加以考虑的一些重要变更. 如果您之前发布过 Android 应用,请注意您的应用可能受到这些平台变更的影响. 电池和内存 Android N 包括旨在延长设备电池寿命和减少 RAM 使用的系统行为变更. 这些变更可能会影响您的应用访问系统资源,以及您的系统通过特定隐式 Intent 与其他应用互动的方式. 低电耗模式 Android 6.0(API 级别 23)引入了低电

Android7.0新特性,及Android N适配

新特性部分 Android 7.0 Nougat 提供新功能以提升性能.生产效率和安全性,主要新增了以下的新特性和优化: 一.新的Notification Android N 增加了许多新的notifications API,进行了重新的设计,引入了新的风格. 模板更新: 开发者将能够充分利用新模板,只需进行少量的代码调整. 消息样式自定义: 新增自定义样式.消息回复.消息分组等更加灵活. 捆绑通知: 系统可以将消息组合在一起(例如,按消息主题)并显示组.用户可以适当地进行 Dismiss 或

Android7.0下载Apk自动安装

Android7.0下载Apk自动安装 1. 整体需求 下载APK文件 使用DownloadManager来下载 在应用界面中展示下载进度 安装下载后的APK文件 root模式: 可以自动安装,不需要用户主动点击 正常模式: 弹出安装应用页面,需要兼容7.0以上版本 2. DownloadManager DownloadManager是Android提供的用于下载的类,使用起来比较简单,它包含两个静态内部类DownloadManager.Query和DownloadManager.Request