1# restool
2
3
4## Overview
5
6restool is a resource compilation tool that creates resource indexes and parses resources by compiling resource files. You can call the [resource management APIs](../reference/apis-localization-kit/js-apis-resource-manager.md) to obtain resources. The tool is stored in the **toolchains** subdirectory of the SDK installation directory.
7
8## Description
9
10The tool supports the following command options.
11
12| Option| Default Value Allowed| Argument Carried| Description|
13| -------- | -------- | -------- | -------- |
14| -i | No| Yes| Resource directory or resource middleware to create. The same command can run multiple times.<br>For details, see [Compiling Resources](#compiling-resources).|
15| -j | No| Yes| Path of the **config.json** or **module.json** file.|
16| -o | No| Yes| Output path of the compiled resource.|
17| -p | No| Yes| Bundle name of the compiled resource.|
18| -r | No| Yes| Header file path of the resource. The header file can be in .txt, .js, or .h format.|
19| -e | Yes| Yes| Start ID of the generated resource, for example, **0x01000000**. The value range is [0x01000000, 0x06FFFFFF) and [0x08000000, 0x41FFFFFF).|
20| -f | Yes| No| An existing output path will be forcibly deleted and a new one will be generated.|
21| -h | Yes| No| Help information.|
22| -m | Yes| Yes| Module name. During joint module compilation, multiple module names can be specified, separated by commas (,).|
23| -x | Yes| Yes| Resource directory for generating intermediate files or a single resource path. The same command can run multiple times.|
24| -z | Yes| No| Compilation result generated based on the resource intermediate file directory.|
25| -v | Yes| No| Tool version.|
26| --ids | Yes| Yes| Output directory of the generated **id_defined.json** file.|
27| --defined-ids | Yes| Yes| Path of the **id_defined.json** file. Generally, the file is generated by using **--ids**.<br>**id_defined.json** contains a list of resource types, names, and IDs.<br>You can customize resource IDs in **id_defined.json**.|
28| --icon-check | Yes| No| Whether to enable PNG image verification for icons and startWindowIcons.|
29| --target-config | Yes| Yes| Used together with the **-i** command to support compilation selection.<br>[Parameter description](#target-config-parameters): Specify the configurations to be included.|
30
31### target-config Parameters
32
33Supported parameters: **MccMnc**, **Locale**, **Orientation**, **Device**, **ColorMode**, and **Density**.
34
35Format: Use semicolons (;\) to separate different parameter configurations. Use square brackets ([]) to encapsulate values for a parameter and use commas (,) to separate values.
36
37**MccMnc** matching rule: The MCC must always be used for matching. If an MNC is not included, a match is found as long as the MCC is the same. If an MNC is included, a match is found when both the MCC and MNC are the same.
38
39**Locale** matching rules:
40
411. The language must always be used for matching.
42
432. If a script (text) is not included, a match is found as long as the language is the same. If a script is included, a match is found when both the language and script are the same.
44
453. If a country/region is not included, a match is found as long as the language is the same. If a country/region is included, a match is found when both the language and country/region are the same.
46
47Example: Locale[zh_CN,en_US];Device[phone]. This configuration uses the languages zh_CN and en_US and the device phone as filter criteria. A match is found only when the resources use zh_CN and en_US as the languages and apply to phones. Other parameters (such as **MccMnc** and **Orientation**) are not configured and any values of them can match.
48
49## Example
50
51An example **entry** directory structure is as follows:
52```
53entry/src/main
54|    |----resource
55|    |    |----base
56|    |    |    |----element
57|    |    |    |----media
58|    |    |    |----profile
59|    |    |----rawfile
60|    |    |----resfile
61|    |----config.json/module.json
62```
63
64### Compiling Resources
65
66There are two resource compilation modes: full resource compilation and incremental resource compilation.
67
681. To compile all resources, run the following command:
69
70```
71restool -i entry/src/main -j entry/src/main/module.json -p com.ohos.demo -o out -r out/ResourceTable.txt -f
72```
73
742. To compile incremental resources, perform the following steps:
75
76Step 1: Generate the resource middleware.
77
78```
79restool -x entry/src/main/resource -o out
80```
81Step 2: Compile the resource middleware.
82
83```
84restool -i out1 -i out2 -o out -p com.ohos.demo -r out/ResourceTable.txt -j entry/src/main/module.json -f -z
85```
86
87### Fixing the Resource ID
88
89To fix the resource ID, perform the following steps:
90
91Step 1: Create the **id_defined.json** file. There are two ways to create the file.
92
93+ Run the following command to generate the file:
94
95```
96restool -i entry/src/main -j entry/src/main/module.json -p com.ohos.demo -o out -r out/ResourceTable.txt --ids out -f
97```
98
99+ Customize the **id_defined.json** file with the following content:
100
101```
102{
103    "record" :
104    [
105        {
106            "id": "0x01000000", // A fixed ID for the resource.
107            "name": "app_name", // Resource name.
108            "type": "string" // Resource type.
109        }
110    ]
111}
112```
113
114Step 2: Fix the resource ID. There are two ways to fix the resource ID.
115
116+ Run the following command to fix the resource ID:
117```
118restool -i entry/src/main -j entry/src/main/module.json -p com.ohos.demo -o out1 -r out1/ResourceTable.txt --defined-ids out/id_defined.json -f
119```
120
121+ Place the customized **id_defined.json** file in the **resource/base/element/** directory and then run the following command to fix the resource ID:
122```
123restool -i entry/src/main -j entry/src/main/module.json -p com.ohos.demo -o out1 -r out1/ResourceTable.txt  -f
124```
125