1page.title=Validate Keymaps Tool
2@jd:body
3
4<!--
5    Copyright 2013 The Android Open Source Project
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18-->
19<p>The Android framework has a small tool called <code>validatekeymaps</code> to validate the
20syntax of input device configuration files, key layout files, key character
21maps files and virtual key definition files.</p>
22<h2 id="compilation">Compilation</h2>
23<p>To compile <code>validatekeymaps</code>, set up the development environment, download
24the Android source tree, compile it, then run:</p>
25<pre><code>$ mmm frameworks/base/tools/validatekeymaps
26</code></pre>
27<p>This command should compile a host tool called validatekeymaps into the
28<code>out/host/&lt;os&gt;/bin</code> directory.</p>
29<h2 id="usage">Usage</h2>
30<p>If you ran <code>envsetup.sh</code> to set up your development environment, then the
31<code>validatekeymaps</code> tool should already be on your path.  You can verify
32this by running <code>validatekeymaps</code>.</p>
33<pre><code>$ validatekeymaps
34
35Keymap Validation Tool
36
37Usage:
38 validatekeymaps [*.kl] [*.kcm] [*.idc] [virtualkeys.*] [...]
39   Validates the specified key layouts, key character maps,
40   input device configurations, or virtual key definitions.
41</code></pre>
42<p>Then all you need to do is run <code>validatekeymaps</code> an give it the path of
43one or more files to validate.</p>
44<pre><code>$ validatekeymaps frameworks/base/data/keyboards/Generic.kl
45
46Validating file 'frameworks/base/data/keyboards/Generic.kl'...
47No errors.
48
49Success.
50</code></pre>
51<p>And if there is an error...</p>
52<pre><code>$ validatekeymaps Bad.kl
53
54Validating file 'Bad.kl'...
55E/KeyLayoutMap(87688): Bad.kl:24: Expected keyword, got 'ke'.
56Error -22 parsing key layout file.
57
58Failed!
59</code></pre>
60<h2 id="automation">Automation</h2>
61<p>It is a <em>very</em> good idea to run <code>validatekeymaps</code> on all configuration files
62before installing them on a device.</p>
63<p>The process can easily be automated as part of the build system by using a
64script or a makefile.</p>
65<p>The following sample makefile is based on the contents of
66<code>frameworks/base/data/keyboards/Android.mk</code>.</p>
67<pre><code># This makefile performs build time validation of framework keymap files.
68
69LOCAL_PATH := $(call my-dir)
70
71# Validate all key maps.
72include $(CLEAR_VARS)
73
74validatekeymaps := $(HOST_OUT_EXECUTABLES)/validatekeymaps$(HOST_EXECUTABLE_SUFFIX)
75files := MyKeyboard.kl MyKeyboard.kcm MyTouchScreen.idc
76
77LOCAL_MODULE := validate_framework_keymaps
78LOCAL_MODULE_TAGS := optional
79LOCAL_REQUIRED_MODULES := validatekeymaps
80
81validate_framework_keymaps: $(files)
82    $(hide) $(validatekeymaps) $(files)
83
84include $(BUILD_PHONY_PACKAGE)
85</code></pre>
86