DEV Community

ZHZL-m
ZHZL-m

Posted on

【Journey of HarmonyOS Next】DevEco Studio User Guide (34) -> Configuration and Build (1)

Image description

1-> Multi-module configuration

1.1 -> Static configuration module

The modules field in the project-level build-profile.json5 configuration file is used to record the module information under the project, including the module name, the source code path of the module, and the target information of the module.

For example, there are two module directories in the following directory, you can add module information to the build-profile.json5 configuration file under the project to bind the module to the project:

Image description

Other Profiles:

oh-package.json5: the third-party package dependency configuration file of the application
local.properties: Applies the local environment configuration file
obfuscation-rules.txt: The obfuscation rule profile of the app module
consumer-rules.txt: The obfuscation rule file exported by the library module by default will be packaged into the HAR package. Only HAR modules are supported
Example module configuration in the build-profile.json5 file in the project:

{
  "modules": [
    {
      "name": "module1", // 模块的名称。该名称需与module.json5文件中的module.name保持一致。在FA模型中,对应的文件为config.json。
      "srcPath": "./module1" // 模块的源码路径,为模块根目录相对工程根目录的相对路径
    },
    {
      "name": "module2",
      "srcPath": "./module2"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

1.2 -> Dynamically configure the module

Hvigor allows you to dynamically add or exclude a module from hvigorconfig.ts scripts.

2-> Module compilation

Hvigor supports modular compilation and packaging. You can build in modules in two ways:

In DevEco Studio, select the module directory to be built, and click "Make module 'module1'" in the Build menu bar, where "module1" is displayed according to the name of the specific project module.
In the Terminal of DevEco Studio, specify the module for compilation. For example, if the module type is entry and the target product is default, you can run the following command to build a HAP module:
hvigorw --mode module -p product=default -p module=module1@default assembleHap

3 -> Add dependencies

Applications/metaservices support the installation, sharing, and distribution of code and management of project dependencies through the package management tool ohpm. This article explains how to add dependencies in your project.

You can specify dependencies in the dependencies/devDependencies fields in the oh-package.json5 file of your project or module, and the above two dependency fields can be referenced in three ways: remote third-party packages, local folders, and local HAR/HSP. The dynamicDependencies in the oh-package.json5 file are limited to the use case of dynamic dependencies HSP. The following configuration takes dependencies as an example.

3.1 -> Remote tripartite package

Set the third-party package dependency in the oh-package.json5 file of the module to which the third-party package needs to be imported, as shown in the following configuration:

"dependencies": {
  "@ohos/lottie": "^2.0.0"
}
Enter fullscreen mode Exit fullscreen mode

3.2 -> Local folder

Set the local folder in the oh-package.json5 file of the module, as shown in the following configuration:

"dependencies": {
  "folder": "file:../folder"
}
Enter fullscreen mode Exit fullscreen mode

3.3 -> Local HAR/HSP packets

To quote HAR:

"dependencies": {
  "package": "file:../package.har"
}
Enter fullscreen mode Exit fullscreen mode

Referencing HSP (only in release mode, building HSP generates a tgz package):

"dependencies": {
  "package": "file:../package.tgz"
}
Enter fullscreen mode Exit fullscreen mode

After the dependency is configured, you need to run the ohpm install command to install the dependency package, which will be stored in the oh_modules directory of the corresponding module.

Top comments (0)