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 Java8 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] 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 file. 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 file is stored.| 109| --hsp-path | No | NA | Path of the HSP file. 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 file is 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 117 118 119## Multi-project Packing Command 120 121If 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. 122 123**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. 124 125>**NOTE** 126> 127>Since API version 12, **versionName** is not verified during multi-project packing. 128 129Packing command example: 130 131``` 132java -jar app_packing_tool.jar --mode multiApp [--hap-list <path>] [--hsp-list <path>] [--app-list <path>] --out-path <option> [--force true] 133``` 134 135**Table 4** Parameters of the multi-project packing command 136 137| Name | Mandatory| Option | Description | 138|------------|-------|-----------|-----------------------------------------------------------------------------------------------------| 139| --mode | Yes | multiApp | Packing mode. Each HAP file to pack into the APP file must pass the validity check. | 140| --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. | 141| --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. | 142| --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.| 143| --out-path | Yes | NA | Path of the target file. The file name extension must be .hqf.| 144| --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. | 145 146 147 148## HQF Packing Command 149 150If 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. 151 152Packing command example: 153 154``` 155java -jar app_packing_tool.jar --mode hqf --json-path <path> [--lib-path <path>] [--ets-path <path>] [--resources-path <path>] --out-path <path> [--force true] 156``` 157 158**Table 5** Parameters of the HQF packing command 159 160| Name | Mandatory| Option | Description | 161|-------------|-------|-------------|------------------------------------| 162| --mode | Yes | hqf | Packing mode. | 163| --json-path | Yes | NA | Path of the JSON file. The file name must be **patch.json**. | 164| --lib-path | No | NA | Path of the library file. | 165| --ets-path | No | NA | Path of the ETS file. | 166| --resources-path | No | NA | Path of the resources file. | 167| --out-path | Yes | NA | Path of the target file. The file name extension must be .hqf. | 168| --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.| 169 170## APPQF Packing Command 171 172An 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. 173 174Packing command example: 175 176``` 177java -jar app_packing_tool.jar --mode appqf --hqf-list <path> --out-path <path> [--force true] 178``` 179 180**Table 6** Parameters of the APPQF packing command 181 182| Name | Mandatory| Option | Description | 183|------------|-------|-------------|------------------------------------| 184| --mode | Yes | appqf | Packing mode. | 185| --hqf-list | Yes | NA | Path of the HQF file. If there are multiple HQF files, separate them with commas (,). | 186| --out-path | Yes | NA | Path of the target file. The file name extension must be .appqf. | 187| --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.| 188 189## versionNormalize Command 190 191For 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. 192 193Packing command example: 194``` 195java -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\ 196``` 197 198**Table 7** Parameters of the versionNormalize command 199 200| Name | Mandatory| Option | Description | 201|----------------|-------|------------------|-------------------------------------------------------------------| 202| --mode | Yes | versionNormalize | Command type. | 203| --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.| 204| --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. | 205| --version-name | Yes | Version name | New version name of the HAP and HSP files. | 206| --out-path | Yes | NA | Target file path, which must be a directory (folder). | 207 208## packageNormalize Command 209 210The **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. 211 212Packing command example: 213``` 214java -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\ 215``` 216 217**Table 8** Parameters of the packageNormalize command 218 219| Name | Mandatory| Option | Description | 220|----------------|-------|---------------|-----------------------------------------------------| 221| --mode | Yes | packageNormalize | Command type. | 222| --hsp-list | Yes | Path of the HSP files | Path of the HSP file. 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.| 223| --bundle-name | Yes | Bundle name | New bundle name, to which the passed-in bundle name will be changed. | 224| --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. | 225| --out-path | Yes | NA | Target file path, which must be a directory (folder). | 226 227## RES Packing Command 228 229Used to generate an HAP file for the **pack.res** file. 230 231Packing command example: 232 233``` 234java -jar app_packing_tool.jar --mode res --entrycard-path <path> --pack-info-path <path> --out-path <path> [--force true] 235``` 236 237**Table 9** Parameters of the RES packing command 238 239| Name | Mandatory| Option | Description | 240|------------------|-------|---------------|------------------------------------| 241| --mode | Yes | res | Command type. | 242| --entrycard-path | Yes | NA | Path of the **pack.res** file. | 243| --pack-info-path | Yes | NA | Path of the **pack.info** file. | 244| --out-path | Yes | NA | Path of the target file. The file name extension must be .res. | 245| --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.| 246 247## FastApp Packing Commands 248 249You 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. 250 251**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. 252 253**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. 254 255Packing command example: 256 257``` 258java -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] 259``` 260 261**Table 10** Parameters of the FastApp packing command 262 263| Name | Mandatory| Option | Description | 264|--------------------|-------|------------|-------------------------------------------------------------------------------------------------------| 265| --mode | Yes | fastApp | Packing mode. Each HAP file to pack into the APP file must pass the validity check. | 266| --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 (,). | 267| --hsp-path | No | NA | Path of the HSP file. 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 (,).| 268| --pack-info-path | Yes | NA | Path of the **pack.info** file. The file name must be **pack.info**. | 269| --out-path | Yes | NA | Path of the target file. The file name extension must be .app. | 270| --signature-path | No | NA | Path of the signature file. | 271| --certificate-path | No | NA | Path of the certificate file. | 272| --pack-res-path | No | NA | Path of the **pack.res** file. | 273| --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. | 274