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).

{
"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"
]
}
]
}
]
} {
"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",
}
]
} 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.
