validatekeymaps tool

The Android framework has a small tool called validatekeymaps to validate the syntax of input device configuration files, key layout files, key character maps files and virtual key definition files.

Compilation

To compile validatekeymaps, set up the development environment, download the Android source tree, compile it, then run:

mmm frameworks/base/tools/validatekeymaps

This command should compile a host tool called validatekeymaps into the out/host/<os>/bin directory.

Usage

If you ran envsetup.sh to set up your development environment, then the validatekeymaps tool should already be on your path. You can verify this by running validatekeymaps.

validatekeymaps

You should see the following output:

Keymap Validation Tool

Usage:
 validatekeymaps [*.kl] [*.kcm] [*.idc] [virtualkeys.*] [...]
   Validates the specified key layouts, key character maps, 
   input device configurations, or virtual key definitions.

Then all you need to do is run validatekeymaps and give it the path of one or more files to validate.

validatekeymaps frameworks/base/data/keyboards/Generic.kl

Example:

Validating file 'frameworks/base/data/keyboards/Generic.kl'...
No errors.

Success.

And if there is an error...

validatekeymaps Bad.kl

Example:

Validating file 'Bad.kl'...
E/KeyLayoutMap(87688): Bad.kl:24: Expected keyword, got 'ke'.
Error -22 parsing key layout file.

Failed!

Automation

It is a very good idea to run validatekeymaps on all configuration files before installing them on a device.

The process can easily be automated as part of the build system by using a script or a makefile.

The following sample makefile is based on the contents of 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)