自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
validatekeymaps 工具
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
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
,然后再将这些文件安装到设备中。
通过使用脚本或 makefile,该过程可以作为构建系统的一部分轻松地自动执行。
以下示例 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 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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```"]]