目录

Developing a Dynamic Shared Package

DevEco Studio supports the development of Harmony Shared Packages (HSPs). They are designed to allow for dynamic, on-demand downloading of functionalities for apps/atomic services, and loading of required packages for atomic services. When there are multiple installation packages that require resource sharing, HSPs can also be utilized to reduce the repetitive packing of common resources and code.

  • In-app HSP: a type of HSP that is closely coupled with an application bundle name (bundleName) during compilation and can be used only by the specified application.
  • Integrated HSP: a type of HSP that is not coupled with any specific application bundle name during the build and release processes and whose bundle name can be automatically replaced by the toolchain with the host application bundle name.

Constraints

Creating an HSP Module

  1. Add a module to a project using either of the following methods:

    • Right-click the top of the project directory and choose New > Module from the shortcut menu.
    • Select any file in the project directory and choose File > New > Module on the menu bar.

  2. Set the template type to Shared Library and click Next.

  3. On the Configure New Module page, set the following parameters and click Finish to create an HSP module.

    • Module name: name of the new module, for example, library.
    • Device type: supported device type.
    • Enable native: whether to create a module for invoking C++ code.
    • C++ Standard: C++ standard library, which can be Toolchain Default, C++11, or C++14. This parameter is required only when Enable native is toggled on. This field is supported since DevEco Studio 6.0.1 Beta1.

    After the creation is complete, the HSP module and related files are generated in the project directory.

Building an HSP Module

If obfuscation is not enabled for the HSP, the HSP will not be obfuscated when it is integrated.

When you have developed the in-app HSP module, select the module name and choose Build > Make Module ${libraryName} on the menu bar to build an HSP.

By default, a HAR is created automatically with an HSP. Therefore, you can find the .har and .hsp files in the build folder of the module directory.

To share an HSP in an app, you must upload the .tgz file for it to a private repository (see Obtaining Third-Party Libraries from ohpm-repo). To generate a .tgz file for an HSP, perform the following:

  1. Click the icon on the toolbar to switch the build mode to release.

  2. Select the root directory of the HSP and choose Build > Make Module ${libraryName} to start the build.

    After the build is complete, the .tgz file is generated in the build folder. You can then upload it to a private repository for sharing in an app.