restool.md 3.4 KB
Newer Older
G
Gloria 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
# restool


## Overview

restool is a resource compilation tool that creates resource indexes and parses resources by compiling resource files. The tool is stored in the **toolchains** subdirectory of the SDK installation directory.

## Description

The tool supports the following command options.

| Option| Default Value Allowed| Argument Carried| Description|
| -------- | -------- | -------- | -------- |
| -i | No| Yes| Resource directory or resource intermediate file directory to create. The same command can run multiple times.|
| -j | No| Yes| Path of the **config.json** or **module.json** file.|
| -o | No| Yes| Output path of the compiled resource.|
| -p | No| Yes| Bundle name of the compiled resource.|
| -r | No| Yes| Header file path of the resource. The header file can be in .txt, .js, or .h format.|
| -e | Yes| Yes| Start ID of the generated resource, for example, **0x01000000**. The value range is [0x01000000, 0x06FFFFFF),[0x08000000, 0x41FFFFFF).|
| -f | Yes| No| An existing output path will be forcibly deleted and a new one will be generated.|
| -h | Yes| No| Help information.|
| -m | Yes| Yes| Module name. During joint module compilation, multiple module names can be specified, separated by commas (,).|
| -x | Yes| Yes| Resource directory for generating intermediate files or a single resource path. The same command can run multiple times.|
| -z | Yes| No| Compilation result generated based on the resource directory.|
| -v | Yes| No| Tool version.|
| --ids | Yes| Yes| Output directory of the generated **id_defined.json** file.|
| --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**.|

## Example

An example **entry** directory structure is as follows:
```
entry/src/main
|    |----resource
|    |    |----base
|    |    |    |----element
|    |    |    |----media
|    |    |    |----profile
|    |    |----rawfile
|    |----config.json/module.json
```

Run the following command to build all resources:

```
restool -i entry/src/main  -j entry/src/main/module.json -p com.ohos.demo -o out -r out/ResourceTable.txt -f
```

To build the resource incrementally (available only in preview mode), perform the following steps:

1. Generate resource middleware.
```
restool -x entry/src/main/resource -o out
```
2. Compile the middleware.
```
restool -i out1 -i out2 -o out -p com.ohos.demo -r out/ResourceTable.txt -j entry/src/main/module.json -f -z
```

The resource ID can be fixed in either of the following ways:

Method 1: Store the custom **id_defined.json** file in the **resource/base/element/** directory. After the build is successful, the generated ID is the same as the custom ID in the **id_defined.json** file.

Method 2: Run the **--ids** command to generate the **id_defined.json** file. The **--defined-ids** command specifies the **id_defined.json** file. After the build is successful, the generated ID is the same as the custom ID in the **id_defined.json** file.

Generate the **id_defined.json** file.
```
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
```

**id_defined.json** file with a fixed resource ID:
```
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
```