1# Packing Tool
2
3The packing tool packs compiled files for installation and release. You can use DevEco Studio or the JAR package of the packaging tool to pack files. The JAR package is usually stored in the **toolchains** directory of the SDK.
4
5The packing tool supports the generation of HAP (module package of the ability type), HSP (dynamically shared package), APP (application program package), HQF (quick fix module package), and APPQF (quick fix package) files.
6
7
8## Constraints
9
10The packing tool must run in Java 8 or later.
11
12
13## HAP Packing Command
14
15You can use the JAR package of the packing tool to generate an HAP file for a module by passing in packing options and file paths.
16
17- Packing command example in the stage model:
18
19
20    ```
21    java -jar app_packing_tool.jar --mode hap --json-path <path> [--resources-path <path>] [--ets-path <path>] [--index-path <path>] [--pack-info-path <path>] [--lib-path <path>] --out-path <path> [--force true] [--compress-level 5] [--pkg-context-path <path>] [--hnp-path <path>]
22    ```
23
24- Packing command example in the FA model:
25
26
27    ```
28    java -jar app_packing_tool.jar --mode hap --json-path <path> [--maple-so-path <path>] [--profile-path <path>] [--maple-so-dir <path>] [--dex-path <path>] [--lib-path <path>] [--resources-path <path>] [--index-path <path>] --out-path <path> [--force true] [--compress-level 5]
29    ```
30
31**Table 1** Parameters of the HAP packing command
32
33| Name            | Mandatory| Option         | Description                                                        | Remarks           |
34| ---------------- | ---------- | ------------- | ------------------------------------------------------------ | --------------- |
35| --mode           | Yes        | hap           | Packing mode.                                                  | NA              |
36| --json-path      | Yes        | NA            | Path of the JSON file. The file name must be **config.json** in the FA model and **module.json** in the stage model.| NA              |
37| --profile-path   | No        | NA            | Path of the **CAPABILITY.profile** file.                                | NA              |
38| --maple-so-path  | No        | NA            | Path of the Maple SO file. The file name extension must be .so. If there are multiple SO files, separate them with commas (,).| NA              |
39| --maple-so-dir   | No        | NA            | Path of the maple SO directory (folder).                                      | NA              |
40| --dex-path       | No        | NA            | Path of the DEX file. The file name extension must be .dex. If there are multiple DEX files, separate them with commas (,).<br>The value can also be the directory (folder) where the DEX file is stored.| NA              |
41| --lib-path       | No        | NA            | Path of the library file.                                             | NA              |
42| --resources-path | No        | NA            | Path of the resources file.                                       | NA              |
43| --index-path     | No        | NA            | Path of the INDEX file. The file name must be **resources.index**.               | NA              |
44| --pack-info-path | No        | NA            | Path of the **pack.info** file. The file name must be **pack.info**.                  | NA              |
45| --rpcid-path     | No        | NA            | Path of the **rpcid.sc** file. The file name must be **rpcid.sc**.                    | NA              |
46| --js-path        | No        | NA            | Path of the JS file.                                        | This parameter is valid only in the stage model.|
47| --ets-path       | No        | NA            | Path of the ETS file.                                       | This parameter is valid only in the stage model.|
48| --out-path       | Yes        | NA            | Path of the target file. The file name extension must be .hap.                      | NA              |
49| --force          | No        | true or false| The default value is **false**. If the value is **true**, an existing target file will be forcibly deleted during packing. | NA              |
50| --an-path        | No        | NA            | Path of the AN file.                                          | This parameter is valid only in the stage model.|
51| --ap-path        | No        | NA            | Path of the AP file.                                          | This parameter is valid only in the stage model.|
52| --dir-list       | No        | NA            | List of directories (folders) to be packed into the HAP file.                     | NA              |
53| --compress-level | No        | number        | Compression level, ranging from 1 to 9. The default value is **1**. This parameter is valid only when **compressNativeLibs** is set to **true**. A larger value indicates a higher compression rate and a slower compression speed.| NA  |
54| --pkg-context-path      | No        | NA            | Path of the **pkgContextInfo.json** file, which contains the context information.| This parameter is valid only in the stage model.             |
55| --hnp-path | No| NA | Path of the native software package to be packed into the HAP file.| NA |
56
57## HSP Packing Command
58
59HSP files enable file sharing among multiple HAPs. You can use the JAR package of the packing tool to generate an HSP file for an application by passing in packing options and file paths.
60
61Packing command example:
62```
63java -jar app_packing_tool.jar --mode hsp --json-path <path> [--resources-path <path>] [--ets-path <path>] [--index-path <path>] [--pack-info-path <path>] [--lib-path <path>] --out-path <path> [--force true] [--compress-level 5] [--pkg-context-path <path>]
64```
65
66**Table 2** Parameters of the HSP packing command
67
68| Name            | Mandatory| Option         | Description                                                        |
69| ---------------- | ---------- | ------------- | ------------------------------------------------------------ |
70| --mode           | Yes        | hsp           | Packing mode.                                                  |
71| --json-path      | Yes        | NA            | Path of the JSON file. The file name must be **module.json**.                    |
72| --profile-path   | No        | NA            | Path of the **CAPABILITY.profile** file.                                |
73| --dex-path       | No        | NA            | Path of the DEX file. The file name extension must be .dex. If there are multiple DEX files, separate them with commas (,).<br>The value can also be the directory (folder) where the DEX file is stored.|
74| --lib-path       | No        | NA            | Path of the library file.                                             |
75| --resources-path | No        | NA            | Path of the resources file.                                       |
76| --index-path     | No        | NA            | Path of the INDEX file. The file name must be **resources.index**.               |
77| --pack-info-path | No        | NA            | Path of the **pack.info** file. The file name must be **pack.info**.                  |
78| --js-path        | No        | NA            | Path of the JS file.                                        |
79| --ets-path       | No        | NA            | Path of the ETS file.                                       |
80| --out-path       | Yes        | NA            | Path of the target file. The file name extension must be .hsp.                      |
81| --force          | No        | true or false| The default value is **false**. If the value is **true**, an existing target file will be forcibly deleted during packing. |
82| --compress-level | No        | number        | Compression level, ranging from 1 to 9. The default value is **1**. This parameter is valid only when **compressNativeLibs** is set to **true**. A larger value indicates a higher compression rate and a slower compression speed.|
83| --pkg-context-path      | No        | NA            | Path of the **pkgContextInfo.json** file, which contains the context information.|
84
85## APP Packing Command
86
87You can use the JAR package of the packing tool to generate an APP file for an application by passing in packing options and file paths. The APP file is used to release the application to the application market.
88
89**HAP validity check**: When packing the HAP files in a project to generate an APP file, ensure that the values of **bundleName**, **versionCode**, **minCompatibleVersionCode**, **debug**, **minAPIVersion**, and **targetAPIVersion** configured in each JSON file of the HAP are the same, and the value of **moduleName** is unique in all the JSON files. For the FA model, you must also ensure that the value of **package** is unique in all the JSON files. The HAP modules must have the same **apiReleaseType**. The **apiReleaseType** of HSP modules is not checked.
90
91**Compression rules**: When packaging the APP files, the HAP and HSP files in release mode are compressed, but the HAP and HSP files in debug mode are not compressed.
92
93>**NOTE**
94>
95>Since API version 12, **versionName** is not verified during application packing.
96
97Packing command example:
98
99```
100java -jar app_packing_tool.jar --mode app [--hap-path <path>] [--hsp-path <path>] --out-path <path> [--signature-path <path>] [--certificate-path <path>] --pack-info-path <path> [--force true] [--encrypt-path <path>]
101```
102
103**Table 3** Parameters of the APP packing command
104
105| Name                | Mandatory| Option         | Description                                                          |
106|--------------------|-------|-------------|--------------------------------------------------------------|
107| --mode             | Yes    | app         | Packing mode. Each HAP file to pack into the APP file must pass the validity check.                                          |
108| --hap-path         | No    | NA          | Path of the HAP files. The file name extension must be .hap. If there are multiple HAP files, separate them with commas (,).<br>The value can also be the directory (folder) where the HAP files are stored.|
109| --hsp-path         | No    | NA          | Path of the HSP files. The file name extension must be .hsp. If there are multiple HSP files, separate them with commas (,).<br>The value can also be the directory (folder) where the HSP files are stored.|
110| --pack-info-path   | Yes    | NA          | Path of the **pack.info** file. The file name must be **pack.info**.                                            |
111| --out-path         | Yes    | NA          | Path of the target file. The file name extension must be .app.                                       |
112| --signature-path   | No    | NA          | Path of the signature file.                                                       |
113| --certificate-path | No    | NA          | Path of the certificate file.                                                       |
114| --pack-res-path    | No    | NA          | Path of the **pack.res** file.                                |
115| --force            | No    | true or false| The default value is **false**. If the value is **true**, an existing target file will be forcibly deleted during packing.                          |
116| --encrypt-path     | No    | NA          | The file name must be **encrypt.json**.                          |
117
118
119
120## Multi-project Packing Command
121
122If multiple teams develop the same application but it is inconvenient to share code, you can use multi-project packing, which packs the packed HAP, HSP, and APP files into a final APP file and releases it to the application market.
123
124**HAP validity check**: Ensure that the values of **bundleName**, **versionCode**, **minCompatibleVersionCode**, **debug**, **minAPIVersion**, **targetAPIVersion**, **compileSdkVersion**, and **compileSdkType** configured in each JSON file of the HAP are the same, the value of **moduleName** is unique in all the JSON files, and the value of **entry** is unique for the same device. For the FA model, you must also ensure that the value of **package** is unique in all the JSON files. The HAP modules must have the same **apiReleaseType**. The **apiReleaseType** of HSP modules is not checked.
125
126>**NOTE**
127>
128>Since API version 12, **versionName** is not verified during multi-project packing.
129
130Packing command example:
131
132```
133java -jar app_packing_tool.jar --mode multiApp [--hap-list <path>] [--hsp-list <path>] [--app-list <path>] --out-path <option> [--force true] [--encrypt-path <path>]
134```
135
136**Table 4** Parameters of the multi-project packing command
137
138| Name        | Mandatory| Option       | Description                                                                                                 |
139|------------|-------|-----------|-----------------------------------------------------------------------------------------------------|
140| --mode     | Yes    | multiApp  | Packing mode. Each HAP file to pack into the APP file must pass the validity check.                                                           |
141| --hap-list | No    | Path of the HAP files   | Path of the HAP files. The file name extension must be .hap. If there are multiple HAP files, separate them with commas (,).<br>The value can also be the directory (folder) where the HAP files are stored.                                         |
142| --hsp-list | No    | Path of the HSP files   | Path of the HSP files. The file name extension must be .hsp. If there are multiple HSP files, separate them with commas (,).<br>The value can also be the directory (folder) where the HSP files are stored.                                         |
143| --app-list | No    | Path of the APP files   | Path of the APP files. The file name extension must be .app. If there are multiple APP files, separate them with commas (,).<br>The value can also be the directory (folder) where the APP files are stored.<br>You must specify **--hap-list**, **--hsp-list**, or **--app-list**, or any of their combinations.|
144| --out-path | Yes    | NA | Path of the target file. The file name extension must be .hqf.|
145| --force    | No    | true or false| The default value is **false**. If the value is **true**, an existing target file will be forcibly deleted during packing.                                                                 |
146| --encrypt-path | No    | Path of **encrypt.json**| The file name must be **encrypt.json**.                                                                 |
147
148
149
150## HQF Packing Command
151
152If you find detects in the application and want to rectify the defects quickly, you can use HQF files. You can use the JAR package of the packing tool to generate an HQF file for an application by passing in packing options and file paths.
153
154Packing command example:
155
156```
157java -jar app_packing_tool.jar --mode hqf --json-path <path> [--lib-path <path>] [--ets-path <path>] [--resources-path <path>] --out-path <path> [--force true]
158```
159
160**Table 5** Parameters of the HQF packing command
161
162| Name         | Mandatory| Option         | Description                                |
163|-------------|-------|-------------|------------------------------------|
164| --mode      | Yes    | hqf         | Packing mode.                             |
165| --json-path | Yes    | NA          | Path of the JSON file. The file name must be **patch.json**.       |
166| --lib-path  | No    | NA          | Path of the library file.                        |
167| --ets-path  | No    | NA          | Path of the ETS file.                      |
168| --resources-path  | No    | NA          | Path of the resources file.                      |
169| --out-path  | Yes    | NA          | Path of the target file. The file name extension must be .hqf.             |
170| --force     | No    | true or false| The default value is **false**. If the value is **true**, an existing target file will be forcibly deleted during packing.|
171
172## APPQF Packing Command
173
174An APPQF file consists of one or more HQF files. These HQF files are split from an APPQF file in the application market and then distributed to specific devices. You can use the JAR package of the packing tool to generate an APPQF file for an application by passing in packing options and file paths.
175
176Packing command example:
177
178```
179java -jar app_packing_tool.jar --mode appqf --hqf-list <path> --out-path <path> [--force true]
180```
181
182**Table 6** Parameters of the APPQF packing command
183
184| Name        | Mandatory| Option         | Description                                |
185|------------|-------|-------------|------------------------------------|
186| --mode     | Yes    | appqf       | Packing mode.                             |
187| --hqf-list | Yes    | NA          | Path of the HQF file. If there are multiple HQF files, separate them with commas (,).             |
188| --out-path | Yes    | NA          | Path of the target file. The file name extension must be .appqf.           |
189| --force    | No    | true or false| The default value is **false**. If the value is **true**, an existing target file will be forcibly deleted during packing.|
190
191## versionNormalize Command
192
193For the same APP, the values of **versionName** and **versionCode** of all the HAP and HSP files must be the same. When only one HAP or HSP needs to be updated, you can run the **versionNormalize** command to unify the versions of these HAP or HSP files. This command changes the version numbers and names of the HAP and HSP files passed in, and generates in the specified directory new HAP and HSP files with the same names and a **version_record.json** file to record their original version numbers and names.
194
195Packing command example:
196```
197java -jar path\app_packing_tool.jar --mode versionNormalize --input-list 1.hap,2.hsp --version-code 1000001 --version-name 1.0.1 --out-path path\out\
198```
199
200**Table 7** Parameters of the versionNormalize command
201
202| Name            | Mandatory| Option              | Description                                                               |
203|----------------|-------|------------------|-------------------------------------------------------------------|
204| --mode         | Yes    | versionNormalize | Command type.                                                            |
205| --input-list   | Yes    | Path of the HAP or HSP files      | Path of the HAP or HSP files. The file name extension must be .hap or .hsp. If there are multiple HAP or HSP files, separate them with commas (,).<br>The value can also be the directory (folder) where the HAP and HSP files are stored. If this is the case, all HAP and HSP files in the directory (folder) are read.|
206| --version-code | Yes    | Internal version number             | New internal version number of the HAP and HSP files. The value must be an integer and cannot be earlier than the version numbers of all the HAP and HSP files passed in.           |
207| --version-name | Yes    | Version name            | New version name of the HAP and HSP files.                                   |
208| --out-path     | Yes    | NA               | Target file path, which must be a directory (folder).                                                  |
209
210## packageNormalize Command
211
212The **packageNormalize** command is used to change the passed-in HSP bundle name and version number and generate an HSP with the same name in the specified directory.
213
214Packing command example:
215```
216java -jar path\app_packing_tool.jar --mode packageNormalize --hsp-list path\1.hsp,path\2.hsp --bundle-name com.example.myapplication --version-code 1000001 --out-path path\out\
217```
218
219**Table 8** Parameters of the packageNormalize command
220
221| Name            | Mandatory| Option           | Description                                                 |
222|----------------|-------|---------------|-----------------------------------------------------|
223| --mode         | Yes    | packageNormalize | Command type.                                              |
224| --hsp-list     | Yes    | Path of the HSP files     | Path of the HSP files. The file name extension must be .hsp. If there are multiple HSP files, separate them with commas (,). The value can also be the directory (folder) where the HSP files are stored.|
225| --bundle-name  | Yes    | Bundle name           | New bundle name, to which the passed-in bundle name will be changed.                            |
226| --version-code | Yes    | Internal version number          | New version number, to which the passed-in version number will be changed. The value must be an integer greater than 0.                |
227| --out-path     | Yes    | NA            | Target file path, which must be a directory (folder).                                    |
228
229## Packing Commands for RES Files
230
231This command is used to generate an HAP file for the **pack.res** file.
232
233Packing command example:
234
235```
236java -jar app_packing_tool.jar --mode res --entrycard-path <path> --pack-info-path <path> --out-path <path> [--force true]
237```
238
239**Table 9** Parameters of the RES packing command
240
241| Name              | Mandatory| Option           | Description                                |
242|------------------|-------|---------------|------------------------------------|
243| --mode           | Yes    | res           | Command type.                             |
244| --entrycard-path | Yes    | NA            | Path of the **pack.res** file.                          |
245| --pack-info-path | Yes    | NA            | Path of the **pack.info** file.             |
246| --out-path       | Yes    | NA            | Path of the target file. The file name extension must be .res.             |
247| --force          | No    | true or false  | The default value is **false**. If the value is **true**, an existing target file will be forcibly deleted during packing.|
248
249## Packing Commands for FastApp Files
250
251You can use the JAR package of the packing tool to generate an APP file for a fast application by passing in packing options and path of the HAP or HSP files. The APP file is used to release the application to the application market.
252
253**HAP validity check**: When packing the HAP files in a project to generate an APP file, ensure that the values of **bundleName**, **versionCode**, **minCompatibleVersionCode**, **debug**, **minAPIVersion**, and **targetAPIVersion** configured in each JSON file of the HAP are the same, and the value of **moduleName** is unique in all the JSON files. The HAP modules must have the same **apiReleaseType**. The **apiReleaseType** of HSP modules is not checked.
254
255**Compression rules**: When packaging the APP files, the HAP and HSP files in release mode are compressed, but the HAP and HSP files in debug mode are not compressed.
256
257Packing command example:
258
259```
260java -jar app_packing_tool.jar --mode fastApp [--hap-path <path>] [--hsp-path <path>] --out-path <path> [--signature-path <path>] [--certificate-path <path>] --pack-info-path <path> [--pack-res-path <path>] [--force true] [--encrypt-path <path>]
261```
262
263**Table 10** Parameters of the FastApp packing command
264
265| Name                | Mandatory| Option        | Description                                                                                                   |
266|--------------------|-------|------------|-------------------------------------------------------------------------------------------------------|
267| --mode             | Yes    | fastApp    | Packing mode. Each HAP file to pack into the APP file must pass the validity check.                                                                                   |
268| --hap-path         | No    | NA         | Path of the HAP file directory, which contains all files of the HAP. If there are multiple HAP file directories, separate them with commas (,).                                             |
269| --hsp-path         | No    | NA         | Path of the HSP files. The file name extension must be .hsp. If there are multiple HSP files, separate them with commas (,). 2. Path of the HSP file directory, which contains all files of the HSP. If there are multiple HSP file directories, separate them with commas (,).|
270| --pack-info-path   | Yes    | NA         | Path of the **pack.info** file. The file name must be **pack.info**.                                                                                     |
271| --out-path         | Yes    | NA         | Path of the target file. The file name extension must be .app.                                                                                |
272| --signature-path   | No    | NA         | Path of the signature file.                                                                                                |
273| --certificate-path | No    | NA         | Path of the certificate file.                                                                                                |
274| --pack-res-path    | No    | NA         | Path of the **pack.res** file.                                                                         |
275| --force            | No    | true or false| The default value is **false**. If the value is **true**, an existing target file will be forcibly deleted during packing.                                                                   |
276| --encrypt-path     | No    | NA         | The file name must be **encrypt.json**.                                                                   |
277