DEV Community

Hongtao Liang
Hongtao Liang

Posted on

[HarmonyOS NEXT] Sign and Package HarmonyOS App (Build Mode: Release)

Introduction

This chapter explains how to add a release certificate, create a release Profile, and sign your application correctly.

Certificate Preparation

First, ensure that a release certificate already exists. If it does, you can skip this step. Each developer account has a single release certificate, which should be used for all apps released under that account.

  1. Click the link below to open the webpage. Log in with an administrator account and click "Certificates, APP IDs, and Profiles":
    https://developer.huawei.com/consumer/en/service/josp/agc/index.html#/

  2. If a valid Release Certificate already exists, you can skip this section.

Key and CSR Generation

  1. In DevEco, go to the menu bar: Build -> Generate Key and CSR

  2. Assuming you have never created a certificate before, create a new folder "~/profiles_backup", and select "New".

  3. In the pop-up window:

    • Key Store file: Select where to save the Key. Here, choose the "~/profiles_backup" folder and name the file key.p12.
    • Password: Enter a password (remember it).
    • Confirm Password: Re-enter the password. Click OK.
  4. Enter an Alias (remember this as well). The window should look like this:

  5. Click Next to complete key creation and proceed to the CSR creation page.

  6. Here, note that the CSR file is the location where the CSR will be saved, not an existing CSR file. Again, select the "~/profiles_backup" folder and name the file csr.csr.

  7. Click Finish to complete. You can now find the generated certificate files in "~/profiles_backup".

Upload Certificate File and Download

Add the certificate in AppGallery. The name can be arbitrary, type should be "Release Certificate", and for CSR select the file you just prepared. After adding, click Download to get the .cer file. It is recommended to save it in the same directory as the CSR, e.g., "~/profiles_backup".

Add Profile and Download

Select your app, select the release certificate, choose the certificate you just added, and click Download Profile. It is best to save it in the same place as your key files, e.g., "~/profiles_backup".

Check Files

You should now have the following files:

  1. .p12 file
  2. .csr file
  3. .cer file
  4. .p7b file

At this point, all the materials required for signing are ready.

Signing

Configure Signing

  1. Open File -> Project Structure

  2. Fill in the signing information and click OK.

  3. Click the target icon in the top right corner, change the build mode to "release", and click Apply to save.

Build

Go to Build -> Build Hap(s)/APP(s) -> Build APP(s)

Output Path

The output path is under the build directory at the same level as AppScope in your project. The file with signed in its name is the signed release package.

Top comments (0)