You can reference third-party HARs or HSPs (third-party packages for short) from the ohpm repository, local folders, or local HAR or HSP files.
ohpm config set registry your_registry1,your_registry2
Note: You can configure multiple repository addresses, separated by commas (,).
cd path/to/your/project/entry ohpm install @ohos/lottie
"dependencies": {
"@ohos/lottie": "^2.0.0"
} After the dependency is set, run the ohpm install command to install it to the oh_modules folder of the module directory.
ohpm install
cd path/to/your/project/entry ohpm install path/to/foo
"dependencies": {
"foo": "file:path/to/foo" // The path can also be a relative path starting from the directory where oh-package.json5 is located.
} After the dependency is set, run the ohpm install command to install it. The source code of the foo module is installed in the oh_modules directory of the entry module.
ohpm install
cd path/to/your/project/entry ohpm install path/to/package.har
cd path/to/your/project/entry ohpm install path/to/package.tgz
"dependencies": {
"package": "file:path/to/package.har" // The path can also be a relative path starting from the directory where oh-package.json5 is located.
}
In the code snippet, package.har indicates the file name of the third-party package. package indicates the dependency name used to reference this third-party package. You are advised to keep it consistent with the name of the third-party package, that is, the name field in the oh-package.json5 file of the third-party package.
"dependencies": {
"package": "file:path/to/package.tgz" // The path can also be a relative path starting from the directory where oh-package.json5 is located.
} After the dependency is set, run the ohpm install command to install it to the oh_modules directory of the module.
ohpm install
When installing or uninstalling a shared package, you can add hooks to the oh-package.json5 file of the project or target module to manage the lifecycle of the install and uninstall commands. The following is an example:
"hooks": {
"preInstall": "echo 00 preInstall", // Before the install command is executed
"postInstall": "echo 00 postInstall", // After the install command is executed
"preUninstall": "echo 00 preUninstall", // Before the uninstall command is executed
"postUninstall": "echo 00 postUninstall" // After the uninstall command is executed
}
Currently, this feature is available only in the Chinese mainland.
Since DevEco Studio 6.0.0 Beta5, the OHPM Index entry has been added, providing efficient filtering and management capabilities of the OpenHarmony Third-Party Library Repository. This improves developer productivity in package selection, reduces risks from information asymmetry, and enables quick discovery and positioning of required open-source third-party libraries.
in the upper-left corner of the page to view a list of installed shared packages. If a package is not the latest version, you can click the Update button to update it, or click the Delete button to remove it.