自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
驗證鍵盤地圖工具
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 架構提供名為 validatekeymaps
的小型工具,可驗證輸入裝置設定檔、按鍵版面配置檔、按鍵字元對應檔案和虛擬按鍵定義檔案的語法。
編譯
如要編譯 validatekeymaps
,請設定開發環境、下載 Android 來源樹狀結構、編譯並執行:
mmm frameworks/base/tools/validatekeymaps
這個指令應將名為 validatekeymaps 的主機工具編譯至 out/host/<os>/bin
目錄。
用量
如果您已執行 envsetup.sh
來設定開發環境,validatekeymaps
工具應已在路徑中。您可以執行 validatekeymaps
來驗證這項資訊。
validatekeymaps
您應該會看到下列輸出結果:
Keymap Validation Tool
Usage:
validatekeymaps [*.kl] [*.kcm] [*.idc] [virtualkeys.*] [...]
Validates the specified key layouts, key character maps,
input device configurations, or virtual key definitions.
接著,您只需執行 validatekeymaps
,並提供一或多個要驗證的檔案路徑即可。
validatekeymaps frameworks/base/data/keyboards/Generic.kl
例子:
Validating file 'frameworks/base/data/keyboards/Generic.kl'...
No errors.
Success.
如果發生錯誤...
validatekeymaps Bad.kl
例子:
Validating file 'Bad.kl'...
E/KeyLayoutMap(87688): Bad.kl:24: Expected keyword, got 'ke'.
Error -22 parsing key layout file.
Failed!
自動化
非常建議您在將所有設定檔安裝到裝置前,先對這些檔案執行 validatekeymaps
。
您可以使用指令碼或 Make 檔案,輕鬆將這個程序自動化,做為建構系統的一部分。
以下範例的 makefile 是根據 frameworks/base/data/keyboards/Android.mk
的內容建立。
# This makefile performs build time validation of framework keymap files.
LOCAL_PATH := $(call my-dir)
# Validate all key maps.
include $(CLEAR_VARS)
validatekeymaps := $(HOST_OUT_EXECUTABLES)/validatekeymaps$(HOST_EXECUTABLE_SUFFIX)
files := MyKeyboard.kl MyKeyboard.kcm MyTouchScreen.idc
LOCAL_MODULE := validate_framework_keymaps
LOCAL_MODULE_TAGS := optional
LOCAL_REQUIRED_MODULES := validatekeymaps
validate_framework_keymaps: $(files)
$(hide) $(validatekeymaps) $(files)
include $(BUILD_PHONY_PACKAGE)
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# validatekeymaps tool\n\nThe Android framework has a small tool called `validatekeymaps` to validate the\nsyntax of input device configuration files, key layout files, key character\nmaps files and virtual key definition files.\n\nCompilation\n-----------\n\nTo compile `validatekeymaps`, set up the development environment, download\nthe Android source tree, compile it, then run: \n\n```\nmmm frameworks/base/tools/validatekeymaps\n```\n\nThis command should compile a host tool called validatekeymaps into the\n`out/host/\u003cos\u003e/bin` directory.\n\nUsage\n-----\n\nIf you ran `envsetup.sh` to set up your development environment, then the\n`validatekeymaps` tool should already be on your path. You can verify\nthis by running `validatekeymaps`. \n\n```\nvalidatekeymaps\n```\n\nYou should see the following output: \n\n```\nKeymap Validation Tool\n\nUsage:\n validatekeymaps [*.kl] [*.kcm] [*.idc] [virtualkeys.*] [...]\n Validates the specified key layouts, key character maps, \n input device configurations, or virtual key definitions.\n```\n\nThen all you need to do is run `validatekeymaps` and give it the path of\none or more files to validate. \n\n```\nvalidatekeymaps frameworks/base/data/keyboards/Generic.kl\n```\n\nExample: \n\n```\nValidating file 'frameworks/base/data/keyboards/Generic.kl'...\nNo errors.\n\nSuccess.\n```\n\nAnd if there is an error... \n\n```\nvalidatekeymaps Bad.kl\n```\n\nExample: \n\n```\nValidating file 'Bad.kl'...\nE/KeyLayoutMap(87688): Bad.kl:24: Expected keyword, got 'ke'.\nError -22 parsing key layout file.\n\nFailed!\n```\n\nAutomation\n----------\n\nIt is a *very* good idea to run `validatekeymaps` on all configuration files\nbefore installing them on a device.\n\nThe process can easily be automated as part of the build system by using a\nscript or a makefile.\n\nThe following sample makefile is based on the contents of\n`frameworks/base/data/keyboards/Android.mk`. \n\n```\n# This makefile performs build time validation of framework keymap files.\n\nLOCAL_PATH := $(call my-dir)\n\n# Validate all key maps.\ninclude $(CLEAR_VARS)\n\nvalidatekeymaps := $(HOST_OUT_EXECUTABLES)/validatekeymaps$(HOST_EXECUTABLE_SUFFIX)\nfiles := MyKeyboard.kl MyKeyboard.kcm MyTouchScreen.idc\n\nLOCAL_MODULE := validate_framework_keymaps\nLOCAL_MODULE_TAGS := optional\nLOCAL_REQUIRED_MODULES := validatekeymaps\n\nvalidate_framework_keymaps: $(files)\n $(hide) $(validatekeymaps) $(files)\n\ninclude $(BUILD_PHONY_PACKAGE)\n```"]]