自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
SDK 扩展
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
SDK 扩展模块用于确定设备的扩展 SDK 级别,并提供供应用查询扩展 SDK 级别的 API。此模块可更新,意即该模块可在 Android 常规发布周期外的时间接收功能更新。
SDK 扩展负责:
- 确定设备的扩展 SDK 级别。
- 为应用提供用于查询扩展 SDK 级别的 API。
- (从 Android 12 开始)确定
BOOTCLASSPATH
、DEX2OATBOOTCLASSPATH
和 SYSTEMSERVERCLASSPATH
环境变量的值。
SDK 扩展模块 (com.android.sdkext
) 采用 APEX 格式,适用于搭载 Android 11 或更高版本的设备。
SDK 扩展模块 (com.google.android.sdkext
) 采用 APEX 格式,包含以下组件:
(从 Android 12 开始)bin/derive_classpath
:在设备启动过程早期运行的原生二进制文件。它会读取系统和其他模块中的各个类路径配置文件,进行合并,然后确定 CLASSPATH
环境变量的定义。
bin/derive_sdk
:此原生二进制文件在设备启动过程的早期运行,会读取其他模块的元数据,以设置与扩展 SDK 相关的系统属性(例如 build.version.extensions.r
)。
javalib/framework-sdkextension.jar
:此文件位于 bootclasspath 中,用于向应用公开用于查询扩展 SDK 级别的 API。
派生扩展 SDK 级别
derive_sdk
程序可读取作为二进制 protobuf 文件存储在每个 APEX 模块内的 etc/sdkinfo.binarypb
子路径中的元数据。如需详细了解 protobuf 结构,请参阅 protobuf
文件。
读取扩展 SDK 级别
SDK 扩展模块在 android.os.ext
软件包中公开了 SdkExtensions
Java 类。使用 getExtensionVersion(int)
方法可读取 SDK 扩展的版本(例如 getExtensionVersion(Build.VERSION_CODES.R)
)。
派生类路径
derive_classpath
服务会读取 /system/etc/classpaths/
和 /apex/*/etc/classpaths/
中的各个配置文件并进行合并。每个配置都以 proto 二进制文件格式存储来自 classpaths.proto
的 protobuf 消息。derive_classpath.cpp
中介绍了用于确定类路径条目顺序的精确合并算法,算法可能会随时间改变。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# SDK Extensions\n\nThe SDK Extensions module decides the extension SDK level of the device and\nprovides APIs for apps to query the extension SDK level. This module is\nupdatable, meaning it can receive updates to functionality outside of the normal\nAndroid release cycle.\n\nSDK Extensions is responsible for:\n\n- Deciding the extension SDK level of the device.\n- Providing APIs for apps to query the extension SDK level.\n- (Starting Android 12) Determining the values for the `BOOTCLASSPATH`, `DEX2OATBOOTCLASSPATH`, and `SYSTEMSERVERCLASSPATH` environment variables.\n\nModule format\n-------------\n\nThe SDK Extensions module (`com.android.sdkext`) is in\n[APEX](/docs/core/ota/apex) format and is available for devices\nrunning Android 11 or higher.\n\nPackage format\n--------------\n\nThe SDK Extensions module (`com.google.android.sdkext`) is in\n[APEX](/devices/tech/ota/apex) format and\ncontains the following components:\n\n- (Starting Android 12) `bin/derive_classpath`: A\n native binary that runs early in the device boot\n process. It reads individual classpath configs files from the system and\n other modules, merges them, and defines the definition of `CLASSPATH`\n environment variables.\n\n- `bin/derive_sdk`: A native binary that runs early in the device boot process\n and reads metadata of other modules to set system properties related to the\n extension SDK (for example, `build.version.extensions.r`).\n\n- `javalib/framework-sdkextension.jar`: This file is on the bootclasspath that\n exposes APIs to apps to query the extension SDK level.\n\nDerive extension SDK level\n--------------------------\n\nThe `derive_sdk` program reads metadata stored as binary protobuf files in the\n`etc/sdkinfo.binarypb` subpath inside each APEX module. For details on protobuf\nstructure, refer to the\n[`protobuf`](https://android.googlesource.com/platform/external/protobuf.git)\nfile.\n\nRead extension SDK level\n------------------------\n\nThe SDK Extensions module exposes an\n[`SdkExtensions`](https://android.googlesource.com/platform/packages/modules/SdkExtensions/)\njava class in the `android.os.ext` package. Use the `getExtensionVersion(int)`\nmethod to read the version of an SDK extension (for example,\n`getExtensionVersion(Build.VERSION_CODES.R)`).\n\nDerive classpaths\n-----------------\n\nThe `derive_classpath` service reads and merges individual config files in\n`/system/etc/classpaths/` and `/apex/*/etc/classpaths/`. Each config stores\nprotobuf message from [`classpaths.proto`](https://android.googlesource.com/platform/packages/modules/common/+/android16-release/proto/classpaths.proto)\nin a proto binary format. The exact merging algorithm that determines the order\nof the classpath entries is described in\n[`derive_classpath.cpp`](https://android.googlesource.com/platform/packages/modules/SdkExtensions/+/android16-release/derive_classpath/derive_classpath.cpp)\nand might change over time."]]