自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
预构建 ABI 使用情况检查工具
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 共享库会不时发生变动,因此,使预构建二进制文件保持最新状态需要投入大量的努力。在 Android 9 或更低版本中,依赖于已移除的库或 ABI 的预构建二进制文件仅在运行时无法成功链接。开发者必须在日志中查找过时的预构建二进制文件。Android 10 中引入了基于符号的 ABI 使用情况检查工具。该检查工具可以在构建时检测过时的预构建二进制文件,以便共享库开发者了解哪些预构建二进制文件可能会因其更改而出现问题,以及哪些预构建二进制文件必须重新构建。
基于符号的 ABI 使用情况检查工具
基于符号的 ABI 使用情况检查工具可模拟主机上的 Android 动态链接器。该检查工具会将预构建二进制文件与其依赖项关联起来,并检查所有未定义的符号是否均已解析。
首先,该检查工具会检查预构建二进制文件的目标架构。如果预构建二进制文件不以 ARM、AArch64、x86 或 x86-64 架构为目标,检查工具将跳过它。
其次,必须在 LOCAL_SHARED_LIBRARIES
或 shared_libs
中列出预构建二进制文件的依赖项。构建系统会将模块名称解析为共享库的匹配变体(即 core
与 vendor
)。
第三,该检查工具会将 DT_NEEDED
条目与 LOCAL_SHARED_LIBRARIES
或 shared_libs
进行比较。具体来说,该检查工具会从每个共享库中提取 DT_SONAME
条目,并将这些 DT_SONAME
与预构建二进制文件中记录的 DT_NEEDED
条目进行比较。如果存在不匹配,系统会发出错误消息。
第四,该检查工具会解析预构建二进制文件中未定义的符号。这些未定义的符号必须在一个依赖项中进行定义,并且符号绑定必须为 GLOBAL
或 WEAK
。如果无法解析某个未定义的符号,系统会发出错误消息。
预构建模块属性
必须在下列两项的其中之一指定预构建二进制文件的依赖项:
- Android.bp:
shared_libs: ["libc", "libdl", "libm"],
- Android.mk:
LOCAL_SHARED_LIBRARIES := libc libdl libm
如果预构建二进制文件被设计为含有一些无法解析的未定义符号,请指定以下内容之一:
- Android.bp:
allow_undefined_symbols: true,
- Android.mk:
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
要使预构建二进制文件跳过 ELF 文件检查,请指定以下内容之一:
- Android.bp:
check_elf_files: false,
- Android.mk:
LOCAL_CHECK_ELF_FILES := false
运行检查工具
该检查工具在 Android 构建流程中涵盖所有 ELF 预构建模块。
如需单独运行该检查工具以缩短周转时间,请运行以下命令:
m check-elf-files
ABI 错误修复程序
该自动修复程序有助于解决 ABI 检查错误。只需使用 Android.bp/Android.mk 作为输入来运行修复程序,然后该修复程序就会将建议的修正方法输出到 stdout。(可选)使用 --in-place
选项运行修复程序,以便使用建议的修正方法直接更新 Android.bp/Android.mk。
对于 Android.bp,请运行以下代码:
m fix_android_bp_prebuilt
# Print the fixed Android.bp to stdout.
fix_android_bp_prebuilt <path-to-Android.bp>
# Update the Android.bp in place.
fix_android_bp_prebuilt --in-place <path-to-Android.bp>
对于 Android.mk,请运行以下代码:
m fix_android_mk_prebuilt
# Print the fixed Android.mk to stdout.
fix_android_mk_prebuilt <path-to-Android.mk>
# Update the Android.mk in place.
fix_android_mk_prebuilt --in-place <path-to-Android.mk>
本页面上的内容和代码示例受内容许可部分所述许可的限制。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,["# Prebuilt ABI usages checker\n\nAndroid shared libraries evolve from time to time. Keeping prebuilt binaries\nup-to-date requires considerable effort. In Android 9\nor earlier, the prebuilt binaries that depend on removed libraries or ABIs only\nfail to link at run-time. Developers have to trace the logs to find the outdated\nprebuilt binaries. In Android 10, a symbol-based ABI\nusages checker is introduced. The checker can detect outdated prebuilt binaries\nat build-time, so that shared library developers can know which prebuilt\nbinaries might be broken by their change and which prebuilt binaries must be\nre-built.\n\nSymbol-based ABI usages checker\n-------------------------------\n\nThe symbol-based ABI usages checker emulates the Android dynamic linker on host.\nThe checker links the prebuilt binary with the dependencies of the prebuilt\nbinary and checks whether all undefined symbols are resolved.\n\nFirst, the checker checks the target architecture of the prebuilt binary. If the\nprebuilt binary does not target ARM, AArch64, x86, or x86-64 architecture, the\nchecker skips the prebuilt binary.\n\nSecond, the dependencies of the prebuilt binary must be listed in\n`LOCAL_SHARED_LIBRARIES` or `shared_libs`. The build system resolves the module\nnames to the matching variant (i.e. `core` vs. `vendor`) of the shared\nlibraries.\n\nThird, the checker compares the `DT_NEEDED` entries to `LOCAL_SHARED_LIBRARIES`\nor `shared_libs`. In particular, the checker extracts the `DT_SONAME` entry from\neach shared libraries and compares these `DT_SONAME` with the `DT_NEEDED`\nentries recorded in the prebuilt binary. If there is a mismatch, an error\nmessage is emitted.\n\nFourth, the checker resolves the undefined symbols in the prebuilt binary. Those\nundefined symbols must be defined in one of the dependencies and the symbol\nbinding must be either `GLOBAL` or `WEAK`. If an undefined symbol cannot be\nresolved, an error message is emitted.\n\nPrebuilts module properties\n---------------------------\n\nDependencies of the prebuilt binary must be specified in one of the following:\n\n- Android.bp: `shared_libs: [\"libc\", \"libdl\", \"libm\"],`\n- Android.mk: `LOCAL_SHARED_LIBRARIES := libc libdl libm`\n\nIf the prebuilt binary is designed to have some **unresolvable undefined\nsymbols**, specify one of the following:\n\n- Android.bp: `allow_undefined_symbols: true,`\n- Android.mk: `LOCAL_ALLOW_UNDEFINED_SYMBOLS := true`\n\nTo have the prebuilt binary skip the ELF file check, specify one of the\nfollowing:\n\n- Android.bp: `check_elf_files: false,`\n- Android.mk: `LOCAL_CHECK_ELF_FILES := false`\n\nRun the checker\n---------------\n\nThe checker covers all ELF prebuilt modules during the Android build process.\n\nTo run the checker alone for faster turnaround times: \n\n m check-elf-files\n\nABI error fixer\n---------------\n\nThe automatic fixer can help resolve ABI check errors. Simply run the fixer with\nthe Android.bp / Android.mk as input, and the fixer would print the suggested\nfix to stdout. Optionally, run the fixer with the `--in-place` option to\ndirectly update the Android.bp / Android.mk with the suggested fix.\n\nFor Android.bp, \n\n m fix_android_bp_prebuilt\n # Print the fixed Android.bp to stdout.\n fix_android_bp_prebuilt \u003cpath-to-Android.bp\u003e\n # Update the Android.bp in place.\n fix_android_bp_prebuilt --in-place \u003cpath-to-Android.bp\u003e\n\nFor Android.mk, \n\n m fix_android_mk_prebuilt\n # Print the fixed Android.mk to stdout.\n fix_android_mk_prebuilt \u003cpath-to-Android.mk\u003e\n # Update the Android.mk in place.\n fix_android_mk_prebuilt --in-place \u003cpath-to-Android.mk\u003e"]]