openharmony 鸿蒙 packing-tool

2023-02-03 浏览 (795)

Packing Tool

The 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.

The 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.

Constraints

The packing tool must run in Java 8 or later.

HAP Packing Command

You 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.

  • Packing command example in the stage model:

    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>]
    
  • Packing command example in the FA model:

    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]
    

Table 1 Parameters of the HAP packing command

NameMandatoryOptionDescriptionRemarks
--modeYeshapPacking mode.NA
--json-pathYesNAPath of the JSON file. The file name must be config.json in the FA model and module.json in the stage model.NA
--profile-pathNoNAPath of the CAPABILITY.profile file.NA
--maple-so-pathNoNAPath of the Maple SO file. The file name extension must be .so. If there are multiple SO files, separate them with commas (,).NA
--maple-so-dirNoNAPath of the maple SO directory (folder).NA
--dex-pathNoNAPath of the DEX file. The file name extension must be .dex. If there are multiple DEX files, separate them with commas (,).
The value can also be the directory (folder) where the DEX file is stored.
NA
--lib-pathNoNAPath of the library file.NA
--resources-pathNoNAPath of the resources file.NA
--index-pathNoNAPath of the INDEX file. The file name must be resources.index.NA
--pack-info-pathNoNAPath of the pack.info file. The file name must be pack.info.NA
--rpcid-pathNoNAPath of the rpcid.sc file. The file name must be rpcid.sc.NA
--js-pathNoNAPath of the JS file.This parameter is valid only in the stage model.
--ets-pathNoNAPath of the ETS file.This parameter is valid only in the stage model.
--out-pathYesNAPath of the target file. The file name extension must be .hap.NA
--forceNotrue or falseThe default value is false. If the value is true, an existing target file will be forcibly deleted during packing.NA
--an-pathNoNAPath of the AN file.This parameter is valid only in the stage model.
--ap-pathNoNAPath of the AP file.This parameter is valid only in the stage model.
--dir-listNoNAList of directories (folders) to be packed into the HAP file.NA
--compress-levelNonumberCompression 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
--pkg-context-pathNoNAPath of the pkgContextInfo.json file, which contains the context information.This parameter is valid only in the stage model.
--hnp-pathNoNAPath of the native software package to be packed into the HAP file.NA

HSP Packing Command

HSP 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.

Packing command example:

java -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>]

Table 2 Parameters of the HSP packing command

NameMandatoryOptionDescription
--modeYeshspPacking mode.
--json-pathYesNAPath of the JSON file. The file name must be module.json.
--profile-pathNoNAPath of the CAPABILITY.profile file.
--dex-pathNoNAPath of the DEX file. The file name extension must be .dex. If there are multiple DEX files, separate them with commas (,).
The value can also be the directory (folder) where the DEX file is stored.
--lib-pathNoNAPath of the library file.
--resources-pathNoNAPath of the resources file.
--index-pathNoNAPath of the INDEX file. The file name must be resources.index.
--pack-info-pathNoNAPath of the pack.info file. The file name must be pack.info.
--js-pathNoNAPath of the JS file.
--ets-pathNoNAPath of the ETS file.
--out-pathYesNAPath of the target file. The file name extension must be .hsp.
--forceNotrue or falseThe default value is false. If the value is true, an existing target file will be forcibly deleted during packing.
--compress-levelNonumberCompression 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.
--pkg-context-pathNoNAPath of the pkgContextInfo.json file, which contains the context information.

APP Packing Command

You 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.

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.

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.

NOTE

Since API version 12, versionName is not verified during application packing.

Packing command example:

java -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>]

Table 3 Parameters of the APP packing command

NameMandatoryOptionDescription
--modeYesappPacking mode. Each HAP file to pack into the APP file must pass the validity check.
--hap-pathNoNAPath of the HAP files. The file name extension must be .hap. If there are multiple HAP files, separate them with commas (,).
The value can also be the directory (folder) where the HAP files are stored.
--hsp-pathNoNAPath 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.
--pack-info-pathYesNAPath of the pack.info file. The file name must be pack.info.
--out-pathYesNAPath of the target file. The file name extension must be .app.
--signature-pathNoNAPath of the signature file.
--certificate-pathNoNAPath of the certificate file.
--pack-res-pathNoNAPath of the pack.res file.
--forceNotrue or falseThe default value is false. If the value is true, an existing target file will be forcibly deleted during packing.
--encrypt-pathNoNAThe file name must be encrypt.json.

Multi-project Packing Command

If 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.

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.

NOTE

Since API version 12, versionName is not verified during multi-project packing.

Packing command example:

java -jar app_packing_tool.jar --mode multiApp [--hap-list <path>] [--hsp-list <path>] [--app-list <path>] --out-path <option> [--force true] [--encrypt-path <path>]

Table 4 Parameters of the multi-project packing command

NameMandatoryOptionDescription
--modeYesmultiAppPacking mode. Each HAP file to pack into the APP file must pass the validity check.
--hap-listNoPath of the HAP filesPath of the HAP files. The file name extension must be .hap. If there are multiple HAP files, separate them with commas (,).
The value can also be the directory (folder) where the HAP files are stored.
--hsp-listNoPath of the HSP filesPath 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.
--app-listNoPath of the APP filesPath of the APP files. The file name extension must be .app. If there are multiple APP files, separate them with commas (,).
The value can also be the directory (folder) where the APP files are stored.
You must specify --hap-list, --hsp-list, or --app-list, or any of their combinations.
--out-pathYesNAPath of the target file. The file name extension must be .app.
--forceNotrue or falseThe default value is false. If the value is true, an existing target file will be forcibly deleted during packing.
--encrypt-pathNoPath of encrypt.jsonThe file name must be encrypt.json.

HQF Packing Command

If 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.

Packing command example:

java -jar app_packing_tool.jar --mode hqf --json-path <path> [--lib-path <path>] [--ets-path <path>] [--resources-path <path>] --out-path <path> [--force true]

Table 5 Parameters of the HQF packing command

NameMandatoryOptionDescription
--modeYeshqfPacking mode.
--json-pathYesNAPath of the JSON file. The file name must be patch.json.
--lib-pathNoNAPath of the library file.
--ets-pathNoNAPath of the ETS file.
--resources-pathNoNAPath of the resources file.
--out-pathYesNAPath of the target file. The file name extension must be .hqf.
--forceNotrue or falseThe default value is false. If the value is true, an existing target file will be forcibly deleted during packing.

APPQF Packing Command

An 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.

Packing command example:

java -jar app_packing_tool.jar --mode appqf --hqf-list <path> --out-path <path> [--force true]

Table 6 Parameters of the APPQF packing command

NameMandatoryOptionDescription
--modeYesappqfPacking mode.
--hqf-listYesNAPath of the HQF file. If there are multiple HQF files, separate them with commas (,).
--out-pathYesNAPath of the target file. The file name extension must be .appqf.
--forceNotrue or falseThe default value is false. If the value is true, an existing target file will be forcibly deleted during packing.

versionNormalize Command

For 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.

Packing command example:

java -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\

Table 7 Parameters of the versionNormalize command

NameMandatoryOptionDescription
--modeYesversionNormalizeCommand type.
--input-listYesPath of the HAP or HSP filesPath 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 (,).
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.
--version-codeYesInternal version numberNew 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.
--version-nameYesVersion nameNew version name of the HAP and HSP files.
--out-pathYesNATarget file path, which must be a directory (folder).

packageNormalize Command

The 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.

Packing command example:

java -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\

Table 8 Parameters of the packageNormalize command

NameMandatoryOptionDescription
--modeYespackageNormalizeCommand type.
--hsp-listYesPath of the HSP filesPath 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.
--bundle-nameYesBundle nameNew bundle name, to which the passed-in bundle name will be changed.
--version-codeYesInternal version numberNew version number, to which the passed-in version number will be changed. The value must be an integer greater than 0.
--out-pathYesNATarget file path, which must be a directory (folder).

Packing Commands for RES Files

This command is used to generate an HAP file for the pack.res file.

Packing command example:

java -jar app_packing_tool.jar --mode res --entrycard-path <path> --pack-info-path <path> --out-path <path> [--force true]

Table 9 Parameters of the RES packing command

NameMandatoryOptionDescription
--modeYesresCommand type.
--entrycard-pathYesNAPath of the pack.res file.
--pack-info-pathYesNAPath of the pack.info file.
--out-pathYesNAPath of the target file. The file name extension must be .res.
--forceNotrue or falseThe default value is false. If the value is true, an existing target file will be forcibly deleted during packing.

Packing Commands for FastApp Files

You 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.

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.

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.

Packing command example:

java -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>]

Table 10 Parameters of the FastApp packing command

NameMandatoryOptionDescription
--modeYesfastAppPacking mode. Each HAP file to pack into the APP file must pass the validity check.
--hap-pathNoNAPath of the HAP file directory, which contains all files of the HAP. If there are multiple HAP file directories, separate them with commas (,).
--hsp-pathNoNAPath 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 (,).
--pack-info-pathYesNAPath of the pack.info file. The file name must be pack.info.
--out-pathYesNAPath of the target file. The file name extension must be .app.
--signature-pathNoNAPath of the signature file.
--certificate-pathNoNAPath of the certificate file.
--pack-res-pathNoNAPath of the pack.res file.
--forceNotrue or falseThe default value is false. If the value is true, an existing target file will be forcibly deleted during packing.
--encrypt-pathNoNAThe file name must be encrypt.json.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Debugging Tools

harmony 鸿蒙Ability Assistant

harmony 鸿蒙Account Manager

harmony 鸿蒙Advanced Notification Manager

harmony 鸿蒙App Check Tool

harmony 鸿蒙Access Token Manager

harmony 鸿蒙Bundle Manager

harmony 鸿蒙Common Event Manager

harmony 鸿蒙devicedebug

harmony 鸿蒙EDM

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/8885e75a8ee34becbaef8a2d6c134011