目录

Examples

Before officially releasing an app, you need to thoroughly debug its code. The build behaviors of the debugging version and official release may be different. You can use buildMode to customize build differences between the two versions.

Assuming that the build product is default, the build behavior varies by build mode: obfuscation is enabled in release mode, and debugging is enabled in debug mode.

The example project contains the entry module that is delivered to the default build product. The module customizes two build modes, debug and release, and binds them to the default build product. The following figure shows a project example (module).

Example of Project-Level build-profile.json5

{
  "app": {
    "signingConfigs": [],
    "products": [
      {
        "name": "default",
        "signingConfig": "default",
        "compatibleSdkVersion": "26.0.0",
        "runtimeOS": "HarmonyOS",
        "buildOption": {
          "strictMode": {
            "caseSensitiveCheck": true,
            "useNormalizedOHMUrl": true
          }
        }
      }
    ],
    "buildModeSet": [
      {
        "name": "debug"
      },
      {
        "name": "release"
      }
    ]
  },
  "modules": [
    {
      "name": "entry",
      "srcPath": "./entry",
      "targets": [
        {
          "name": "default",
          "applyToProducts": [
            "default"
          ]
        }
      ]
    }
  ]
}

Example of Module-Level build-profile.json5

[h2]Entry Module

{
  "apiType": "stageMode",
  "buildOption": {
  },
  "buildOptionSet": [
    {
      "name": "release",
      "arkOptions": {
        "obfuscation": {
          "ruleOptions": {
            "enable": true,
            "files": [
              "./obfuscation-rules.txt"
            ]
          }
        }
      }
    },
    {
      "name": "debug",
      "debuggable": true,
      "arkOptions": {
        "obfuscation": {
          "ruleOptions": {
            "enable": false
          }
        }
      }
    }
  ],
  "buildModeBinder": [
    {
      "buildModeName": "release",
      "mappings": [
        {
          "buildOptionName": "release",
          "targetName": "default"
        }
      ]
    },
    {
      "buildModeName": "debug",
      "mappings": [
        {
          "buildOptionName": "debug",
          "targetName": "default"
        }
      ]
    }
  ],
  "targets": [
    {
      "name": "default",
    },
    {
      "name": "ohosTest",
    }
  ]
}

Specifying a Build Mode

[h2]Command Line Tool

Example 1: When building an app, if the build product is default and the build mode is debug, run the following command:

hvigorw --mode project -p product=default -p buildMode=debug assembleApp

The figure below shows an example of the build product.

Example 2: When building an app, if the build product is default and the build mode is release, run the following command:

hvigorw --mode project -p product=default -p buildMode=release assembleApp

The figure below shows an example of the build product.

[h2]DevEco Studio GUI

On the DevEco Studio GUI, set Product to default and Build Mode to debug, and choose Build > Build HAP(s)/APP(s) > Build APP(s). An app package with the build product being default and build mode being debug will be generated.