Integrate mPaaS features

更新时间:
复制 MD 格式

This topic describes how to quickly integrate mPaaS features into your HarmonyOS NEXT app.

Prerequisites

  • You have installed the latest version of the HarmonyOS NEXT development environment, which supports API 12 or later.

  • You have a physical device or an emulator that runs HarmonyOS 3.0.0.22 or later. To learn how to use an emulator, see HarmonyOS Emulator.

  • You have created an app in the mPaaS console and downloaded the .config configuration file for HarmonyOS NEXT. For more information, see Create an app and get the configuration file for HarmonyOS NEXT.

Note

If you have already integrated a beta version, follow these steps to ensure a smooth upgrade.

Procedure

  1. Rename the .config configuration file to mpaas.config and copy it to the entry/resource/rawfile directory of your app's main project.

    Screenshot 2024-01-23 at 14

  2. Install the mppm plugin.

    1. Install and configure the Node.js environment.

      Ensure that Node.js v18 or later is installed and configured. You can check your version by running the node -v command. For more information, see the official Node.js website.

    2. Install mppm.

      Run the following command in your terminal to install mppm.

      Note
      npm install @alipay-inc/oh-mpaas-cli -g
    3. If you are using Windows, you must also configure the Node.js environment variables, including npm-global and npm-global/bin, as shown in the following figure. You can run the npm config get prefix command to view the environment variable path. The command typically returns a path similar to C:\Users\<username>\.npm-global.image

    4. After the installation is complete, run the mppm -v command to verify the installed version.

    5. Rename the .config configuration file to mpaas.config and copy it to the entry/resource/rawfile directory of your app's main project.

  3. Initialize the project.

    Run the mppm init command to initialize your project. This command configures the necessary mPaaS settings for HarmonyOS. You must run this command in theDevEco Studio terminal.

    1. In the DevEco Studio terminal, navigate to your main project's root directory and run the mppm init command, as shown in the following figure.image

    2. Select a baseline.

      Select the 10.2.3 baseline and press the Enter key.

      imageAfter you complete this step, mppm creates a .mprc file in your project's root directory. This file contains information about the baseline, as shown in the following figures.imageimage

    3. Select the components to install. Previously installed components are selected automatically.

      Use the arrow keys to move the cursor, press the spacebar to select or deselect a component, and then press the Enter key.image

      Important

      In compliance with the latest HarmonyOS naming conventions, customers who have previously integrated the data synchronization feature must update the baseline from @mpaas/sync-service to @mpaas/sync_service.

    4. If you are a Windows user and encounter the error shown in the following figure,image you can manually run ohpm clean and ohpm install to pull the SDK.

    5. Currently, mppm only supports automatically installing dependencies into the entry directory. To upgrade mppm in the future, follow the instructions in the release notes. After the installation is complete, the dependencies are added to the oh-package.json5 file in the entry directory.image

  4. Get the security image.

    To get the security image, ensure the mpaas.config file is in the rawfile directory.

    Run the mppm fetch-image command. Use the --finger and --secret options to configure the signature and appsecret. The finger option specifies the fingerprint of the app signature, and the secret option specifies the value of appsecret from the mPaaS console. If you do not configure these two options, the fetch operation fails. After a successful fetch, the images are placed in the rawfile directory under entry.image

    Options

    • --finger: Specifies the fingerprint.

    • --secret: Specifies the appsecret.

    Example

    mppm fetch-image --finger xxxxxx --secret xxxx

Three ways to get the fingerprint

Method 1: From the certificate

  1. During HarmonyOS app development, you obtain a .p7b certificate file used for app signing. From this file, extract the value of the distribution-certificate field. If this field does not exist, extract the value of the development-certificate field. Export the extracted value to a .cer file, such as xxx.cer.
    When you export the file, replace the \n characters with actual line breaks to ensure the format is correct.

  2. Use the keytool utility (DevEco Studio\jbr\bin\keytool.exe) to print the certificate's fingerprint. Run the command: keytool -printcert -file xxx.cer.

Method 2: From your code

import bundleManager from '@ohos.bundle.bundleManager';

let info = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO);
let finger = info.signatureInfo.fingerprint; // This is the fingerprint value.

Method 3: Using the bm command (requires the HAP file to be installed on a physical device)

hdc shell
bm dump -n bundleName | grep fingerprint