1e41f4b71Sopenharmony_ci# HAP
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe Harmony Ability Package (HAP) is the basic unit for installing and running applications. A HAP is a module package consisting of code, resource files, third-party libraries, and an application configuration file. There are two types of HAPs: entry and feature.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci- entry: main module of and entry to an application, providing the basic application functionality.
6e41f4b71Sopenharmony_ci- feature: dynamic feature module of an application, extending the application functionality. This type of HAP can be installed based on user needs and device types.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ciAn application package can contain either only one entry HAP or one entry HAP plus one or more feature HAPs.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## When to Use
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci- Single HAP: If your application only uses the UIAbility (that is, no ExtensionAbility is required), a single HAP (entry HAP) is recommended. While a HAP can contain one or more UIAbilities, adopt the "one UIAbility + multiple pages" mode to avoid unnecessary resource loading.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci- Multi-HAP: If your application needs to use ExtensionAbilities, develop multiple HAPs (one entry HAP and one or more feature HAPs) for it, with each HAP containing one UIAbility or one ExtensionAbility. Note that repeated packaging may arise if these HAPs reference the same library file.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## Constraints
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci- APIs and ArkUI components cannot be exported from the HAP to other modules.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci- In an App Pack that contains multiple HAPs, each type of device supports only one entry HAP and zero, one, or more feature HAPs.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci- If an application has multiple HAPs, the settings of the following parameters must be consistent across the configuration files of these HAPs: **bundleName**, **versionCode**, **versionName**, **minCompatibleVersionCode**, **debug**, **minAPIVersion**, **targetAPIVersion**, and **apiReleaseType**. The value of **moduleName** for any HAP of the same device type must be unique. The IDE validates the settings of these parameters when packaging the HAPs into an App Pack.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci- If an application has multiple HAPs, the signing certificates of all HAPs and HSPs of this application must be the same. Applications are released to the application market in the form of App Pack after being signed. Before distribution, the application market splits an App Pack into HAPs and resigns them to ensure the consistency of HAP signing certificates. Before installing HAPs on a device through the CLI or DevEco Studio for debugging purposes, ensure that their signing certificates are the same. Otherwise, the installation will fail.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci## Creating a HAP
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ciTo create a HAP in DevEco Studio:
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci1. Create a project to build the first ArkTS application.
32e41f4b71Sopenharmony_ci2. Right-click the project directory and choose **New** > **Module** from the shortcut menu.
33e41f4b71Sopenharmony_ci3. In the dialog box displayed, select **Empty Ability** as the template and click **Next**.
34e41f4b71Sopenharmony_ci   
35e41f4b71Sopenharmony_ci4. On the module configuration page, set **Module name**, **Module Type**, and **Device Type**, and click **Next**.
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci5. On the ability configuration page, set **Ability name** and click **Finish**.
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci## Developing a HAP
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci- You can add a UIAbility or ExtensionAbility to a HAP. For details, see <!--RP1-->[Adding an Ability to a Module](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V2/add_new_ability-0000001053183674-V2)<!--RP1End-->.
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci- You can also configure a HAP to reference a HAR or HSP. For details, see [Using a HAR](./har-package.md#using-a-har) and [Using an HSP](./in-app-hsp.md#using-an-hsp).
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci## Debugging a HAP
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ciAfter building code into one or more HAPs and installing or updating these HAPs, you can debug them. For details about how to build the same HAP into different versions based on the deployment environment, target user group, and running environment, see <!--RP2-->[Customizing Multi-Target and Multi-Product Builds](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V2/customized-multi-targets-and-products-0000001430013853-V2)<!--RP2End-->.
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ciTo debug a HAP, use either of the following tools:
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci- Method 1: Use DevEco Studio for debugging. For details, see <!--RP3-->[Debugging Configuration](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V2/ide_debug_device-0000001053822404-V2#section10491183521520)<!--RP3End-->.
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci- Method 2: Use <!--Del-->[<!--DelEnd-->hdc<!--Del-->](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/subsys-toolchain-hdc-guide.md)<!--DelEnd--> (obtained from the **toolchains** directory in the OpenHarmony SDK) for debugging.
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci   Before debugging a HAP, install or update it using either of the methods:
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci   - Use hdc to install and update the HAP.
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci      When specifying the HAP, use the path to it on the operating system. In the following example, the operating system is Windows:
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci      ```shell
62e41f4b71Sopenharmony_ci      // Installation and update: Multiple file paths can be specified.
63e41f4b71Sopenharmony_ci      hdc install entry.hap feature.hap
64e41f4b71Sopenharmony_ci      // Execution result
65e41f4b71Sopenharmony_ci      install bundle successfully.
66e41f4b71Sopenharmony_ci      // Uninstall
67e41f4b71Sopenharmony_ci      hdc uninstall com.example.myapplication
68e41f4b71Sopenharmony_ci      // Execution result
69e41f4b71Sopenharmony_ci      uninstall bundle successfully.
70e41f4b71Sopenharmony_ci      ```
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci   - Run the hdc shell command, and then use the Bundle Manager (bm) tool to install and update the HAP.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci      When specifying the HAP, use the path to it on the real device. The sample code is as follows:
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci      ```shell
77e41f4b71Sopenharmony_ci      // Run the hdc shell command before using the bm tool.
78e41f4b71Sopenharmony_ci      hdc shell
79e41f4b71Sopenharmony_ci      // Installation and update: Multiple file paths can be specified.
80e41f4b71Sopenharmony_ci      bm install -p /data/app/entry.hap /data/app/feature.hap
81e41f4b71Sopenharmony_ci      // Execution result
82e41f4b71Sopenharmony_ci      install bundle successfully.
83e41f4b71Sopenharmony_ci      // Uninstall
84e41f4b71Sopenharmony_ci      bm uninstall -n com.example.myapplication
85e41f4b71Sopenharmony_ci      // Execution result
86e41f4b71Sopenharmony_ci      uninstall bundle successfully.
87e41f4b71Sopenharmony_ci      ```
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci   After the HAP is installed or updated, you can debug it by following the instructions in [Ability Assistant](../tools/aa-tool.md).
90