自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
启用 VNDK
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
为了在供应商与系统之间实现关注点分离,供应商原生开发套件 (VNDK) 需要对代码库进行一些更改。请按照以下指南在供应商/OEM 代码库中启用 VNDK。
构建系统库
构建系统包含多种类型的对象,其中包括库(共享、静态或头文件)和二进制文件。
图 1. 编译系统库。
core
库位于系统映像中,由系统映像使用。此类库不能由 vendor
、vendor_available
、vndk
或 vndk-sp
库使用。
cc_library {
name: "libThatIsCore",
...
}
vendor-only
(或 proprietary
)库位于供应商映像中,由供应商映像使用。
cc_library {
name: "libThatIsVendorOnly",
proprietary: true,
# or: vendor: true, # (for things in AOSP)
...
}
vendor_available
库位于供应商映像中,由供应商映像使用(可能包含 core
的副本)。
cc_library {
name: "libThatIsVendorAvailable",
vendor_available: true,
...
}
vndk
库位于系统映像中,由供应商映像使用。
cc_library {
name: "libThatIsVndk",
vendor_available: true,
vndk: {
enabled: true,
}
...
}
vndk-sp
库由供应商映像使用,同时也由系统映像间接使用。cc_library {
name: "libThatIsVndkSp",
vendor_available: true,
vndk: {
enabled: true,
support_system_process: true,
}
...
}
llndk
库同时由系统映像和供应商映像使用。cc_library {
name: "libThatIsLlndk",
llndk: {
symbol_file: "libthatisllndk.map.txt"
}
...
}
当库标记为 vendor_available:true
时,它将构建两次:
- 一次是为平台构建(因此被安装到
/system/lib
中)
- 一次是为供应商构建(因此被安装到
/vendor/lib
或 VNDK APEX 中)
库的供应商版本使用 -D__ANDROID_VNDK__
标记构建。您可以使用此标记停用在 Android 未来版本中可能会发生显著变化的专用系统组件。此外,不同的库会导出一组不同的头文件(如 liblog
)。您可以在 Android.bp
文件中指定目标的供应商变体特有的选项:
target: { vendor: { … } }
为代码库启用 VNDK
要为代码库启用 VNDK,请执行以下操作:
- 通过计算
vendor.img
和 system.img
分区的所需大小来确定是否符合条件。
- 启用
BOARD_VNDK_VERSION=current
。您可以将其添加到 BoardConfig.mk
,也可以直接使用它来构建组件(例如 m -j BOARD_VNDK_VERSION=current MY-LIB
)。
启用 BOARD_VNDK_VERSION=current
后,构建系统会强行实施以下依赖项和头文件要求。
管理依赖项
如果 vendor
对象依赖的 core
组件在 vndk
中不存在或未以 vendor
对象的形式存在,必须通过以下某种方式解决该问题:
- 可以移除该依赖项。
- 如果该
core
组件归 vendor
所有,可以将其标记为 vendor_available
或 vendor
。
- 可以在上游向 Google 提交更改请求,以便将此核心对象列入
vndk
。
此外,如果有 core
组件依赖于 vendor
组件,就必须使该 vendor
组件成为 core
组件,或者以其他方式移除这种依赖关系(例如,通过移除该依赖项或将其移到 vendor
组件中)。
必须移除全局头文件依赖项,构建系统才能知道在构建头文件时是否带 -D__ANDROID_VNDK__
。例如,您仍然可以使用头文件库 libutils_headers
访问 utils/StrongPointer.h
等 libutils 头文件。
某些头文件(例如 unistd.h
)不能再以传递方式包含,但可以在本地包含。
最后,private/android_filesystem_config.h
的公共部分已移至 cutils/android_filesystem_config.h
。如需管理这些头文件,请执行下列操作之一:
- 通过将所有
AID_*
宏替换为 getgrnam
/getpwnam
调用(如果可能),移除对 private/android_filesystem_config.h
的依赖。例如:
(uid_t)AID_WIFI
变为 getpwnam("wifi")->pw_uid
。
(gid_t)AID_SDCARD_R
变为 getgrnam("sdcard_r")->gr_gid
。
如需了解详情,请参阅 private/android_filesystem_config.h
。
- 对于硬编码的 AIS,请包含
cutils/android_filesystem_config.h
。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-04。
[null,null,["最后更新时间 (UTC):2025-03-04。"],[],[],null,["# Enable VNDK\n\nThe Vendor Native Development Kit (VNDK) requires several changes to a codebase to separate\nconcerns between vendor and system. Use the following guide to enable VNDK in a vendor/OEM\ncodebase.\n\nBuild system libraries\n----------------------\n\nThe build system contains several types of objects including libraries\n(shared, static, or header) and binaries.\n\n**Figure 1.** Build system libraries.\n\n- `core` libraries are used by the system image, on the system image. These libraries can't be used by `vendor`, `vendor_available`, `vndk`, or `vndk-sp` libraries. \n\n ```carbon\n cc_library {\n name: \"libThatIsCore\",\n ...\n }\n ```\n- `vendor-only` (or `proprietary`) libraries are used by the vendor image, on the vendor image. \n\n ```carbon\n cc_library {\n name: \"libThatIsVendorOnly\",\n proprietary: true,\n # or: vendor: true, # (for things in AOSP)\n ...\n }\n ```\n- `vendor_available` libraries are used by the vendor image, on the vendor image (may contain duplicates of `core`). \n\n ```carbon\n cc_library {\n name: \"libThatIsVendorAvailable\",\n vendor_available: true,\n ...\n }\n ```\n- `vndk` libraries are used by the vendor image, on the system image. \n\n ```carbon\n cc_library {\n name: \"libThatIsVndk\",\n vendor_available: true,\n vndk: {\n enabled: true,\n }\n ...\n }\n ```\n- `vndk-sp` libraries are used by the vendor image, and also by the system image indirectly. \n\n ```carbon\n cc_library {\n name: \"libThatIsVndkSp\",\n vendor_available: true,\n vndk: {\n enabled: true,\n support_system_process: true,\n }\n ...\n }\n ```\n- `llndk` libraries are used by both the system and vendor images. \n\n ```carbon\n cc_library {\n name: \"libThatIsLlndk\",\n llndk: {\n symbol_file: \"libthatisllndk.map.txt\"\n }\n ...\n }\n ```\n\nWhen a lib is marked as `vendor_available:true`, it's built\ntwice:\n\n- Once for platform (and thus installed to `/system/lib`)\n- Once for vendor (and thus installed to `/vendor/lib` or VNDK APEX)\n\nThe vendor versions of libs are built with `-D__ANDROID_VNDK__`.\nPrivate system components that may change significantly in future versions of\nAndroid are disabled with this flag. In addition, different libraries export a\ndifferent set of headers (such as `liblog`). Options specific to a\nvendor variant of a target can be specified in an `Android.bp` file\nin: \n\n```text\ntarget: { vendor: { … } }\n```\n\nEnable VNDK for a codebase\n--------------------------\n\nTo enable the VNDK for a codebase:\n\n1. Determine eligibility by calculating the required sizes of `vendor.img` and `system.img` partitions.\n2. Enable `BOARD_VNDK_VERSION=current`. You can add to `BoardConfig.mk` or build components with it directly (for example, `m -j BOARD_VNDK_VERSION=current `\u003cvar translate=\"no\"\u003eMY-LIB\u003c/var\u003e).\n\nAfter enabling `BOARD_VNDK_VERSION=current`, the build system\nenforces the following dependency and header requirements.\n\n### Manage dependencies\n\nA `vendor` object that depends on a `core` component\nthat doesn't exist in `vndk` or as a `vendor` object\nmust be resolved using one of the following options:\n\n- The dependency can be removed.\n- If the `core` component is owned by `vendor`, it can be marked as `vendor_available` or `vendor`.\n- A change making the core object part of the `vndk` may be upstreamed to Google.\n\nIn addition, if a `core` component has dependencies on a\n`vendor` component, the `vendor` component must be made\ninto a `core` component **or** the dependency must be\nremoved in another way (for example, by removing the dependency or by moving the\ndependency into a `vendor` component).\n\n### Manage headers\n\nGlobal header dependencies must be removed to enable the build system to know\nwhether to build the headers with or without `-D__ANDROID_VNDK__`.\nFor example, libutils headers such as `utils/StrongPointer.h` can\nstill be accessed using the header library\n[`libutils_headers`](https://android.googlesource.com/platform/system/core/+/android16-release/libutils/include/utils).\n\nSome headers (such as `unistd.h`) can no longer be included transitively\nbut can be included locally.\n\nFinally, the public part of `private/android_filesystem_config.h`\nhas been moved to `cutils/android_filesystem_config.h`. To manage\nthese headers, do one of the following:\n\n- Remove the dependency to `private/android_filesystem_config.h` by replacing all `AID_*` macros with [getgrnam](http://man7.org/linux/man-pages/man3/getgrnam.3.html)/ [getpwnam](http://man7.org/linux/man-pages/man3/getpwnam.3.html) calls if possible. For example:\n - `(uid_t)AID_WIFI` becomes `getpwnam(\"wifi\")-\u003epw_uid`.\n - `(gid_t)AID_SDCARD_R` becomes `getgrnam(\"sdcard_r\")-\u003egr_gid`.\n\n For details, refer to [private/android_filesystem_config.h](https://android.googlesource.com/platform/system/core/+/android16-release/libcutils/include/private/android_filesystem_config.h).\n- For hard-coded AIS, include `cutils/android_filesystem_config.h`."]]