9f3a45c6创建于 2025年12月19日历史提交

Application Package Structure in Stage Model

This topic explores the structure of an application package in different phases of application development – development phase, build phase, and release phase.

Package Structure in the Development Phase

Create a project in DevEco Studio and try to create multiple modules of different types. To gain a better understanding of the application package structure in the development phase, you are advised to learn this topic by referring to the directory in a real project.

Figure 1 Project structure (for reference only)

project

NOTE

  • The AppScope directory is automatically generated by DevEco Studio. If the directory name is changed, the configuration files and resources in the current directory cannot be loaded. As a result, a compilation error is reported. Therefore, do not change the directory name.
  • The module directory name can be automatically generated by DevEco Studio (for example, entry and library) or customized. For ease of description, ModuleName is used below to represent the module directory name.

The table below lists the main file types in the project structure.

File Type Description
Configuration files A collection of application-level and module-level configurations.
- AppScope > app.json5: application-wide configuration, such as the bundle name, version number, application icon, application name, and dependent SDK version number.
- ModuleName > src > main > module.json5: basic information, supported device types, component information, and required permissions of the module.
ArkTS source code files ModuleName > src > main > ets: ArkTS source code files of the module.
Resource files A collection of application-level and module-level resource files, including images, multimedia, strings, and layout files. For details, see Resource Categories and Access.
- AppScope > resources: resource files required for the application.
- ModuleName > src > main > resources: resource files required for the module.
Other configuration files A collection of files used for compilation and building, including build configuration files, build scripts, obfuscation rule files, and files declaring dependencies.
- build-profile.json5: project-level or module-level build configuration file, including the application signature and product configuration.
- hvigorfile.ts: project-level or module-level build task script. Developers can customize the build tool version and configuration parameters that control the build behavior.
- obfuscation-rules.txt: obfuscation rule file. When obfuscation is enabled, DevEco Studio compiles, obfuscates, and compresses code during builds in Release mode.
- oh-package.json5: stores information about dependent libraries, including the dependent third-party libraries and shared packages.

Package Structure in the Build Phase

Depending on its type, a module is built into a HAP, a HAR, or an HSP. Then you can use DevEco Studio or a packaging tool to package the module into an App Pack and release it to the AppGallery. When the HAP and HSP are built, the HARs on which they depend are packaged into them. Therefore, only the .hap and .hsp files are contained in the App Pack. Below you can see the mapping between the development view (in the development phase) and the view after build and packaging (in the build phase).

Figure 2 Mapping between the development view and the view after build and packaging

app-view

The module file is changed from the development state to the compilation state as follows:

  • ets directory: The ArkTS source code files are built into .abc files.
  • resources directory: The resource files in the AppScope directory are merged into this directory. If files with the same name exist in these two directories, the ones in the AppScope directory are retained after build and packaging.
  • Module configuration file: Fields in the app.json5 file in the AppScope directory are integrated into the module.json5 file in the Module_name directory, generating the final module.json file for the created HAP or HSP.

Package Structure in the Release Phase

Each application contains at least one HAP and zero, one or more HSPs. The collection of HAP and HSP files in an application is called a bundle, and the bundle name is the unique identifier of the application. For details, see the bundleName tag in the app.json5 configuration file.

To release an application to the application market, the bundle must be first packed into an Application Package (App Pack) in .app format. With the packing, DevEco Studio automatically generates a pack.info file, which describes the attributes of each HAP and HSP in the App Pack, including the application-level information (bundle name and version code) and module-level information (name, type, and abilities).

NOTE

  • App Pack is the basic unit used to release an application to the AppGallery.
  • Applications are signed in the units of HAP, HSP, and App Pack, while they are distributed from the cloud and installed on the device in the units of HAP and HSP.

Figure 3 Compilation, release, and deployment process

hap-release