1e41f4b71Sopenharmony_ci# restool 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_cirestool 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. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci## Description 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ciThe tool supports the following command options. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci| Option| Default Value Allowed| Argument Carried| Description| 13e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 14e41f4b71Sopenharmony_ci| -i | No| Yes| [Resource directory](#compiling-resources) or [resource intermediate file directory](#compiling-resources) to create. The same command can run multiple times.| 15e41f4b71Sopenharmony_ci| -j | No| Yes| Path of the **config.json** or **module.json** file.| 16e41f4b71Sopenharmony_ci| -o | No| Yes| Output path of the compiled resource.| 17e41f4b71Sopenharmony_ci| -p | No| Yes| Bundle name of the compiled resource.| 18e41f4b71Sopenharmony_ci| -r | No| Yes| Header file path of the resource. The header file can be in .txt, .js, or .h format.| 19e41f4b71Sopenharmony_ci| -e | Yes| Yes| Start ID of the generated resource, for example, **0x01000000**. The value range is [0x01000000, 0x06FFFFFF) and [0x08000000, 0x41FFFFFF).| 20e41f4b71Sopenharmony_ci| -f | Yes| No| An existing output path will be forcibly deleted and a new one will be generated.| 21e41f4b71Sopenharmony_ci| -h | Yes| No| Help information.| 22e41f4b71Sopenharmony_ci| -m | Yes| Yes| Module name. During joint module compilation, multiple module names can be specified, separated by commas (,).| 23e41f4b71Sopenharmony_ci| -x | Yes| Yes| Resource directory for generating intermediate files or a single resource path. The same command can run multiple times.| 24e41f4b71Sopenharmony_ci| -z | Yes| No| Compilation result generated based on the resource intermediate file directory.| 25e41f4b71Sopenharmony_ci| -v | Yes| No| Tool version.| 26e41f4b71Sopenharmony_ci| --ids | Yes| Yes| Output directory of the generated **id_defined.json** file.| 27e41f4b71Sopenharmony_ci| --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**.| 28e41f4b71Sopenharmony_ci| --icon-check | Yes| No| Whether to enable PNG image verification for icons and startWindowIcons.| 29e41f4b71Sopenharmony_ci| --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.| 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci### target-config Parameters 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ciSupported parameters: **MccMnc**, **Locale**, **Orientation**, **Device**, **ColorMode**, and **Density** 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciFormat: Use semicolons (;) to separate different parameter configurations. Use square brackets ([]) to encapsulate values for a parameter and use commas (,) to separate values. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**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. 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**Locale** matching rules: 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci1. The language must always be used for matching. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci2. 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. 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci3. 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. 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ciExample: 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. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci## Example 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ciAn example **entry** directory structure is as follows: 52e41f4b71Sopenharmony_ci``` 53e41f4b71Sopenharmony_cientry/src/main 54e41f4b71Sopenharmony_ci| |----resource 55e41f4b71Sopenharmony_ci| | |----base 56e41f4b71Sopenharmony_ci| | | |----element 57e41f4b71Sopenharmony_ci| | | |----media 58e41f4b71Sopenharmony_ci| | | |----profile 59e41f4b71Sopenharmony_ci| | |----rawfile 60e41f4b71Sopenharmony_ci| | |----resfile 61e41f4b71Sopenharmony_ci| |----config.json/module.json 62e41f4b71Sopenharmony_ci``` 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci### Compiling Resources 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ciThere are two resource compilation modes: full resource compilation and incremental resource compilation. 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci1. To compile all resources, run the following command: 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci``` 71e41f4b71Sopenharmony_cirestool -i entry/src/main -j entry/src/main/module.json -p com.ohos.demo -o out -r out/ResourceTable.txt -f 72e41f4b71Sopenharmony_ci``` 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci2. To compile incremental resources, perform the following steps: 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ciStep 1: Generate the resource middleware. 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci``` 79e41f4b71Sopenharmony_cirestool -x entry/src/main/resource -o out 80e41f4b71Sopenharmony_ci``` 81e41f4b71Sopenharmony_ciStep 2: Compile the resource middleware. 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci``` 84e41f4b71Sopenharmony_cirestool -i out1 -i out2 -o out -p com.ohos.demo -r out/ResourceTable.txt -j entry/src/main/module.json -f -z 85e41f4b71Sopenharmony_ci``` 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci### Fixing the Resource ID 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ciTo fix the resource ID, perform the following steps: 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ciStep 1: Create the **id_defined.json** file. There are two ways to create the file. 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci+ Run the following command to generate the file: 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci``` 96e41f4b71Sopenharmony_cirestool -i entry/src/main -j entry/src/main/module.json -p com.ohos.demo -o out -r out/ResourceTable.txt --ids out -f 97e41f4b71Sopenharmony_ci``` 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci+ Customize the **id_defined.json** file with the following content: 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci``` 102e41f4b71Sopenharmony_ci{ 103e41f4b71Sopenharmony_ci "record" : 104e41f4b71Sopenharmony_ci [ 105e41f4b71Sopenharmony_ci { 106e41f4b71Sopenharmony_ci "id": "0x01000000", // A fixed ID for the resource. 107e41f4b71Sopenharmony_ci "name": "app_name", // Resource name. 108e41f4b71Sopenharmony_ci "type": "string" // Resource type. 109e41f4b71Sopenharmony_ci } 110e41f4b71Sopenharmony_ci ] 111e41f4b71Sopenharmony_ci} 112e41f4b71Sopenharmony_ci``` 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ciStep 2: Fix the resource ID. There are two ways to fix the resource ID. 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci+ Run the following command to fix the resource ID: 117e41f4b71Sopenharmony_ci``` 118e41f4b71Sopenharmony_cirestool -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 119e41f4b71Sopenharmony_ci``` 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci+ Place the customized **id_defined.json** file in the **resource/base/element/** directory and then run the following command to fix the resource ID: 122e41f4b71Sopenharmony_ci``` 123e41f4b71Sopenharmony_cirestool -i entry/src/main -j entry/src/main/module.json -p com.ohos.demo -o out1 -r out1/ResourceTable.txt -f 124e41f4b71Sopenharmony_ci``` 125