DEV Community

wei chang
wei chang

Posted on

A Detailed Explanation of how to Upload third-party libraries to the ohpm Repository in HarmonyOS Development

Two days ago, Youlan Jun uploaded his first third-party library to the ohpm repository and fully experienced the upload process of ohpm. He felt it was rather complicated, so he would like to share the upload process and some precautions with everyone.
First, let me introduce how to develop a third-party library. Right-click on the project name, create a new Module, select static library, and try to use lowercase letters when naming to avoid uppercase letters.

Image description

Image description

After creation, a directory of third-party libraries will appear in the project. You can write your third-party library code here. After the development is completed, there is still some work to be done.
First, configure the necessary information in the oh-package.json5 file of the third-party library directory:
name: Name
version: Version number
description: Description
main: Entry
author: Author
license: Open Source Agreement
In addition, create three new files and fill in the information carefully:

  1. README.md Here, describe what functions your third-party library has, how to install and use it
  2. CHANGELOG.md Fill in the change content of each version number
  3. LICENSE Here, the license file and open source agreement corresponding to the license in OW-Package.json5 need to be filled in. For example, if the license states "Apache-2.0", the corresponding license file should be written here. After all these are completed, click the packaging command under the Build menu. After the packaging is completed, there will be an additional "build" folder under the third-party library directory. The "outputs" directory within it contains the packaged third-party library files.

Image description

To ensure that it can be used normally after uploading, you can test it locally first. The method for locally invoking the third-party library is to import the third-party library in the oh-package.json5 file of the project directory:

Image description

Then the third-party libraries can be used in the project.
Here's an introduction on how to upload a third-party repository to the ohpm repository
Enter the Personal center:

Image description

First of all, certification management should be carried out:

Image description

Clicking "Add" will pop up an input box for the title and public key. You can write the title freely. Regarding the public key, open the terminal to execute

ssh-keygen -m PEM -t RSA -b 4096 -f ~/.ssh_ohpm/mykey

~/.ssh_ohpm/mykey is the file path of the private key file mykey, specified according to the actual situation. The specified private key storage directory must exist.
Where is this directory? Take mac as an example. My files are in the USER/ USER/.ssh folder. So what am I doing

ssh-keygen -m PEM -t RSA -b 4096 -f /Users/用户名/.ssh/ohpm_rsa

To execute the command, a password needs to be entered. Remember this password as it will be used when uploading the library file
After execution, two files will be created, one with the.pub suffix and the other without a suffix. .pub is the public key file. Copy the content into the public key input box.
The file without a suffix is the private key file. We need to perform the following configuration. For the ohpm command, it needs to be executed in DevEco:

ohpm config set key_path ~/.ssh_ohpm/mykey

Next, you need to configure the release id. In the ohpm personal center, there is a copy release code. Copy the following and execute the following command:

ohpm config set publish_id your_publish_id

your_publish_id is the copied publishing code
The last step is to push the third-party repository to the remote repository:

ohpm publish

Don't forget to enter a password here, as mentioned earlier.
After the upload is completed, the system will automatically enter the review process. On working days, this review is relatively fast. Once the review is passed, you can see your third-party database in the ohpm center. # Third-party SDK## Tool Efficiency #

Top comments (0)