自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
預建 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 做為輸入內容,即可執行修正程式,修正程式會將建議的修正內容列印到標準輸出端。您可以選擇使用 --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 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],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"]]