[Huawei Developers] riteshchanchal:
Introduction

Security of the code and build is very important for all developers. To ensure it, Harmony has different levels of certificates to issue to run the application. In this article, we are going to learn about generating these certificates and the procedure to run the build on the real device. Following are the certificates which we required to generate the build.

1. KeyStore (*.p12)

2. Profile File (*.p7b)

3. CertPath File (*.cer)

Requirements

1. DevEco IDE

2. Huawei Developer Account

Flow Chart

View attachment 5207015

View attachment 5207017

Certificate generation process

KeyStore file generation

Step 1: Create the project on the console, navigate to AG connect, select My Apps, and Add app.

View attachment 5207019

Step 2: Choose Build > Generate Key

Step 3: Click New in Generate Key window.

Step 4: Enter details in Create Key Store and click OK, IDE will generate a .p12 file to given path.

CSR file generation

Step 1: After generating it add remaining details and click on the Generate Key and CSR.

Step 2: Select CSR File Path and, then click OK. Your CSR file will be generated.

Step 3: Two files will be generated on the path you have provided (.csr and .p12).

CER file generation

Step 1: Navigate to AppGallery connect, then open users and permissions.

Step 2: Choose Certificate management > New certificate, upload .csr file generated, and then click Submit.

Step 3: Your certificate will be listed on the users and permission section, from there you can download the .cer file.

Adding device on the console

Step 1: Install the DevEco assistant application on your android smartphone (You can download it from AppGallery), then connect the watch through the Huawei health application. Then open the app and find out the UDID.

Step 2: Get the UDID of your device using the DevEco assistant application.

Step 3: Choose Device management > Add device, enter details in Device information and then click Submit.

Provision file generation

Step 1: Now go back to your application window.

Step 2: Then select the HAP Provision profile from the left menu.

Step 3: Click Add and enter details, and then click Submit.

Step 4: Add the required details on the console.

Step 5: At the end, you will be generated with two files one is a provisional file (.p7b) and another on is Certpath file (.cer). Come back to the IDE and add the certificates to the project structure (Choose File > Project Structure).

Step 6: Add the certificates in Modules.

Step 7: Click Apply, and then click OK.

Build and run the application

Step 1: Now build the Haps as given on the screenshot.

Step 2: Find the Hap file on build folder of your module.

Step 3: Copy the file and paste on the /sdcard/haps folder of your Android smartphone.

Step 4: Find the newly added application on the DevEco assistant app. It shows the application which is there on the /sdcard/haps path.

Step 4: Click install, it will start the installation and wait for the success toast message. Once you get the success toast you can see your application on your wearable.

Tips and Tricks

There are only two debug and one release certificates allowed at a time in the AG console. So make sure that you are saved the .csr file for the future use.

Even if you remove the certificate from the console also, the app will work properly without any issue.

Don’t add package name which is having more than 30 characters. Right now only 30 characters are accepted on the Lite wearable.

Conclusion

In this article, we are learned how to generate and add the required certificate to run and release the application. We have also learned about the DevEco Assistant app.

Reference

Building your app documentation:

HarmonyOS Document

developer.harmonyos.com

Harmony Official document:

Document

developer.harmonyos.com

DevEco Studio User guide:

Document

developer.harmonyos.com