• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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](#compiling-resources) or [resource intermediate file directory](#compiling-resources) to create. The same command can run multiple times.|
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 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
30## Example
31
32An example **entry** directory structure is as follows:
33```
34entry/src/main
35|    |----resource
36|    |    |----base
37|    |    |    |----element
38|    |    |    |----media
39|    |    |    |----profile
40|    |    |----rawfile
41|    |----config.json/module.json
42```
43
44### Compiling Resources
45
46There are two resource compilation modes: full resource compilation and incremental resource compilation.
47
481. To compile all resources, run the following command:
49
50   ```
51   restool -i entry/src/main -j entry/src/main/module.json -p com.ohos.demo -o out -r out/ResourceTable.txt -f
52   ```
53
542. To compile incremental resources, perform the following steps:
55
56   Step 1: Generate the resource middleware.
57
58   ```
59   restool -x entry/src/main/resource -o out
60   ```
61
62   Step 2: Compile the resource middleware.
63
64   ```
65   restool -i out1 -i out2 -o out -p com.ohos.demo -r out/ResourceTable.txt -j entry/src/main/module.json -f -z
66   ```
67
68### Fixing the Resource ID
69
70To fix the resource ID, perform the following steps:
71
72Step 1: Create the **id_defined.json** file. There are two ways to create the file.
73
74+ Run the following command to generate the file:
75
76  ```
77  restool -i entry/src/main -j entry/src/main/module.json -p com.ohos.demo -o out -r out/ResourceTable.txt --ids out/id_defined.json -f
78  ```
79
80+ Customize the **id_defined.json** file with the following content:
81
82  ```
83  {
84      "record" :
85      [
86          {
87              "id": "0x01000000", // A fixed ID for the resource.
88              "name": "app_name", // Resource name.
89              "type": "string" // Resource type.
90          }
91      ]
92  }
93  ```
94
95Step 2: Fix the resource ID. There are two ways to fix the resource ID.
96
97+ Run the following command to fix the resource ID:
98
99  ```
100  restool -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
101  ```
102
103+ Place the customized **id_defined.json** file in the **resource/base/element/** directory and then run the following command to fix the resource ID:
104
105  ```
106  restool -i entry/src/main -j entry/src/main/module.json -p com.ohos.demo -o out1 -r out1/ResourceTable.txt  -f
107  ```