• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# CLI-based Quick Fix Development
2
3You can use the command-line tool to develop a quick fix file, an expeditious approach to resolve application bugs. In this document, an application with the bundle name of **com.ohos.quickfix** in version 1000000 is used as an example to describe how to develop a quick fix file with the command-line tool.
4
5## Writing the patch.json File
6
7Write a **patch.json** file that meets your project requirements and place it in any directory of the project. (Configuring the **patch.json** file is not supported in DevEco Studio.) Create a **patch.json** file on the local computer. Below is an example of the file content:
8```json
9{
10    "app" : {
11        "bundleName" : "com.ohos.quickfix",
12        "versionCode": 1000000, // Application version
13        "versionName" : "1.0.0.1",
14        "patchVersionCode": 1000000, // Patch version
15        "patchVersionName" : "1.0.0.1"
16    },
17    "module" : {
18        "name" : "entry",
19        "type" : "patch",
20        "deviceTypes" : [
21            "default",
22            "tablet"
23        ],
24        "originalModuleHash": "11223344556677889900" // SHA-256 value of the HAP file to restore
25    }
26}
27```
28
29## Generating a Quick Fix File
30### Quick Fix for TS Code
31* After modifying the TS code file in DevEco Studio and build it into a HAP file, you can find the corresponding .abc file in the project directory, for example, **build\default\cache\default\LegacyCompileETS\jsbundle\temporary\pages\index.abc**.
32
33### Quick Fix for C++ Code
34
35* In DevEco Studio, build the original C++ code into a .so file. Fix bugs in the code and rebuild the code into a new .so file. You can find this .so file in the project directory, for example, **build\default\intermediates\libs\default\arm64-v8a\libentry.so**.
36* Locate the **diff.exe** tool in the **toolchains** folder in the local OpenHarmony SDK path. Use this tool to generate a quick fix .so file based on the old and new .so files. The command is as follows:
37```shell
38$ diff.exe -s Example.z.so -d Example.z.so -p Example.z.so.diff
39```
40The command contains the following options:
41- -**s**: path to the old .so file
42- -**d**: path to the new .so file
43- -**p**: path of the generated differential file
44
45## Generating a Quick Fix File in .hqf Format
46
47With the preceding **patch.json**, .abc, and .so files, run the following command to generate an .hqf file using the **app_packing_tool.jar** tool in the **toolchains** folder in the local OpenHarmony SDK path:
48```shell
49$ java -jar app_packing_tool.jar --mode hqf --json-path patch.json --lib-path libs --ets-path patchs --out-path entry-default-unsigned.hqf --force true
50```
51
52The command contains the following options.
53| Option|Description | Remarks|
54| --- | --- |---|
55| mode  |Mode. | Mandatory|
56| json-path|Path to the **patch.json** file.|Mandatory|
57| lib-path|Path to the quick fix .so file. For details about the path, see [Structure of the Quick Fix Package](quickfix-principles.md#structure-of-the-quick-fix-package).|Optional|
58| ets-path|Path to the quick fix .abc file.|Optional|
59
60## Signing the Quick Fix File
61
62Use the [hapsigner](../security/hapsigntool-guidelines.md) tool to sign the **entry-default-unsigned.hqf** file, in the same way you sign a HAP file. To be specific, run the following command to use **hap-sign-tool.jar** in the **toolchains** folder in the local OpenHarmony SDK path:
63
64```shell
65$ java -jar hap-sign-tool.jar sign-app -keyAlias "OpenHarmony Application Release" -signAlg "SHA256withECDSA" -mode "localSign" -appCertFile "OpenHarmonyApplication.pem" -profileFile "ohos_provision_release.p7b" -inFile "entry-default-unsigned.hqf" -keystoreFile "OpenHarmony.p12" -outFile "entry-signed-release.hqf" -keyPwd "123456" -keystorePwd "123456"
66```
67
68## Installing the Quick Fix File
69
70Push the **entry-signed-release.hqf** file to the device.
71```shell
72hdc.exe file send .\entry-signed-release.hqf /data/
73```
74
75Run the following command to install the quick fix file as a patch:
76```shell
77$ bm quickfix -a -f /data/entry-signed-release.hqf
78```
79
80The complete commands are as follows:
81```
82$ bm quickfix -h
83usage: bm quickfix <options>
84options list:
85-h, --help                                   list available commands
86-q, --query                                  indicates query quickfix, used with -b or --bundle-name
87-b, --bundle-name <bundle-name>              query quickfix status and information by a specified bundle name
88-a, --apply                                  indicates apply quickfix, used with -f or --file-path
89-f, --file-path <file-path>                  apply a quickfix file by a specified path
90-f, --file-path <file-path> <file-path> ...  apply some quickfix files of one bundle
91-f, --file-path <bundle-direction>           apply quickfix files by direction, under which are quickfix files
92```
93