Harmonyos Configuration File Elements

This section describes all attributes in the application configuration file config.json.

DevEco Studio offers two views for you to edit the config.json file, namely, Code and Visualized. You can change the view in the upper right corner of the config.json editing window.Figure 1 Visualized view for editing the config.json file

Internal Structure of the Configuration File

The config.json file consists of three mandatory tags, namely, app, deviceConfig, and module. For details about the internal structure of the configuration file, see Table 1.

AttributeDescriptionData TypeInitial Value Allowed
appIndicates the global configuration of an application. Different HAP files of the same application must use the same app configuration.ObjectNo
deviceConfigIndicates the application configuration applied to a specific type of devices.ObjectNo
moduleIndicates the configuration of a HAP file. The module configuration is valid only for the current HAP file.ObjectNo

Internal Structure of the app Tag

The app tag provides the global configuration information of an application. For details about the internal structure, see Table 2.

AttributeSub-attributeDescriptionData TypeInitial Value Allowed
bundleNameIndicates the bundle name of the application. It uniquely identifies the application.The bundle name can contain only letters, digits, underscores (_), and periods (.). It must start with a letter.The value is a string with 7 to 127 bytes of a reverse domain name, for example, com.huawei.himusic. It is recommended that the first label of this attribute is the top-level domain com, the second label is the vendor or individual name, and the third label is the application name. Multiple labels are supported.NOTEIf you want to use the APIs of the ohos.data.orm bundle, the application bundle name cannot contain uppercase letters.StringNo
vendorDescribes the application vendor. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)
versionIndicates the version information of the application.ObjectNo
nameIndicates the application version number visible to users. The value can contain a maximum of 127 bytes and be customized based on the following rules:API 5 and earlier versions: A three-segment version number is recommended, for example, A.B.C (two-segment format A.B is also supported). The values of AB, and C are integers ranging from 0 to 999. Other formats are not supported.A indicates the major version number.B indicates the minor version number.C indicates the patch version number.API 6 and later versions: A four-segment version number is recommended, for example, A.B.C.D. In the version number, AB, and C are integers ranging from 0 to 99, and D is an integer ranging from 0 to 999.A indicates the major version number.B indicates the minor version number.C indicates the feature version number.D indicates the patch version number.StringNo
codeIndicates the application version number used only for application management by HarmonyOS. This version number is not visible to users of the application. The value rules are as follows:API 5 and earlier versions: It is a non-negative integer less than 32 bits in binary mode, converted from the value of version.name as follows:code = A x 1,000,000 + B x 1,000 + CFor example, if version.name is 2.2.1, the value of code is 2002001.API 6 and later versions: The value of code is no longer associated with version.name. You can customize the value. The value is a non-negative integer less than 231. You must update code each time the application version is updated, and the value for a later version must be greater than that of the earlier version.NumberNo
minCompatibleVersionCodeIndicates the minimum compatible version of the application. It is used to check whether the application is compatible with the version on other devices in the cross-device scenario.The value rules are the same as those of version.code.NumberNo (initial value: code attribute value)
smartWindowSizeIndicates the size of the emulated window of the application when it is opened in floating window mode.The value is in the format “Positive integer x Positive integer”, in the unit of vp.The positive integer range is 200 to 2000.StringYes (initial value: left empty)
smartWindowDeviceTypeIndicates the types of devices on which the application can be opened using the emulated window.The value can be:phone: phonestablet: tabletstv: smart TVsArray of stringsYes (initial value: left empty)
targetBundleListIndicates the applications that can be started without installation. The value is a list of bundle names of HarmonyOS applications. Multiple bundle names are separated using commas (,). A maximum of 10 bundle names can be configured.If the target application does not support the installation-free mode, it fails to be started.StringYes (initial value: left empty)

Example of the app tag structure:

"app": {    "bundleName": "com.huawei.hiworld.example",     "vendor": "huawei",     "version": {        "code": 2,         "name": "2.0"    }}

Internal Structure of the deviceConfig Tag

The deviceConfig tag describes the configuration of the application on a specific type of devices. This tag may consist of the defaultphonetablettvcarwearableliteWearable, and smartVision sub-tags. The default configuration applies to all types of devices. You need to declare the peculiar configuration of a specific device type in the associated sub-tag of this type. For details about the internal structure, see Table 3.

AttributeDescriptionData TypeInitial Value Allowed
defaultIndicates the application configuration applied to all types of devices.ObjectNo
phoneIndicates the application configuration specific to smartphones.ObjectYes (initial value: left empty)
tabletIndicates the application configuration specific to tablets.ObjectYes (initial value: left empty)
tvIndicates the application configuration specific to smart TVs.ObjectYes (initial value: left empty)
carIndicates the application configuration specific to head units.ObjectYes (initial value: left empty)
wearableIndicates the application configuration specific to wearables.ObjectYes (initial value: left empty)
liteWearableIndicates the application configuration specific to lite wearables.ObjectYes (initial value: left empty)
smartVisionIndicates the application configuration specific to smart cameras.ObjectYes (initial value: left empty)

For details about the internal structures of the preceding sub-tags, see Table 4.

AttributeDescriptionData TypeInitial Value Allowed
jointUserIdIndicates the user ID shared by applications.Generally, applications run in different processes, and resources used by the applications are isolated. However, in some cases, you may develop multiple applications that need to share resources with each other. This resource sharing is implemented based on the same jointUserId value on the premise that the applications have the same signature.This attribute takes effect only for system applications and applies only to smartphones, tablets, smart TVs, head units, and wearables.This attribute is not supported since API Version 3 and later.StringYes (initial value: left empty)
processIndicates the name of the process running the application or ability.If the process attribute is configured in the deviceConfig tag, all abilities of the application run in this process. You can set the process attribute for a specific ability in the abilities attribute, so that the ability can run in the particular process.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringYes (initial value: bundle name of the application)
supportBackupSpecifies whether the application supports backup and restoration. If this attribute is set to false, backup or restoration will not be performed for the application.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.BooleanYes (initial value: false)
compressNativeLibsSpecifies whether the libs libraries are packaged in the HAP file after being compressed. If this attribute is set to false, the libs libraries are stored without being compressed and will be directly loaded during the installation of the HAP file.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.BooleanYes (initial value: true)
networkIndicates the network security configuration. You can customize the network security settings of the application in the security statement of the configuration file without modifying the application code.ObjectYes (initial value: left empty)

AttributeDescriptionData TypeInitial Value Allowed
cleartextTrafficSpecifies whether to allow the application to use plaintext network traffic, for example, plaintext HTTP traffic.true: The application is allowed to use plaintext traffic.false: The application is not allowed to use plaintext traffic.BooleanYes (initial value: false)
securityConfigIndicates the network security configuration of the application.ObjectYes (initial value: left empty)

AttributeSub-attributeDescriptionData TypeInitial Value Allowed
domainSettingsIndicates the security settings of the custom network domain. This attribute allows nested domains. To be more specific, the domainSettings object of a large domain can be nested with the domainSettings objects of small network domains.ObjectYes (initial value: left empty)
cleartextPermittedSpecifies whether plaintext traffic can be transmitted in the custom network domain. If both cleartextTraffic and securityConfig are declared, whether plaintext traffic can be transmitted in the custom network domain is determined by the cleartextPermitted attribute.true: Plaintext traffic can be transmitted.false: Plaintext traffic cannot be transmitted.BooleanNo
domainsIndicates the domain name configuration. This attribute consists of the subdomains and name sub-attributes.subdomains (boolean): specifies whether the domain name contains subdomains. If this sub-attribute is set to true, the domain naming convention applies to all related domains and subdomains (including the lower-level domains of the subdomains). Otherwise, the convention applies only to exact matches.name (string): indicates the domain name.Array of objectsNo

Example of the deviceConfig tag structure:

 "deviceConfig": {    "default": {        "process": "com.huawei.hiworld.example",         "supportBackup": false,        "network": {            "cleartextTraffic": true,             "securityConfig": {                "domainSettings": {                    "cleartextPermitted": true,                     "domains": [                        {                            "subdomains": true,                             "name": "example.ohos.com"                        }                    ]                }            }        }    }}

Internal Structure of the module Tag

The module tag describes the configuration information of the HAP file. For details about the internal structure, see Table 7.

AttributeDescriptionData TypeInitial Value Allowed
mainAbilityIndicates the name of the entry ability for the HAP file. The value must be the name of an existing Page ability in module > abilities.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringNo if any ability using the Page template exists
packageIndicates the structure name of the HAP file. The value must be unique in the application. The value is a string with a maximum of 127 bytes, in the reverse domain name notation. It is recommended that the value be the same as the project directory of the HAP file.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringNo
nameIndicates the class name of the HAP file. The value is a string with a maximum of 255 bytes, in the reverse domain name notation. The prefix must be the same as the package value specified for this module. Alternatively, the value can start with a period (.) followed by the class name.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringNo
descriptionDescribes the HAP file. The value is a string with a maximum of 255 bytes. If the value exceeds 255 bytes or needs to support multiple languages, you can use a resource index to the description.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringYes (initial value: left empty)
supportedModesIndicates the running mode supported by the application. Currently, only the drive mode is supported.This attribute applies only to head units.Array of stringsYes (initial value: left empty)
deviceTypeIndicates the type of devices on which the abilities can run. The value can be phone (phones), tablet (tablets), tv (smart TVs), car (head units), wearable (wearables), and liteWearable (lite wearables).Array of stringsNo
distroIndicates the distribution description of the current HAP file.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.ObjectNo
metaDataIndicates the metadata of the HAP file.ObjectYes (initial value: left empty)
abilitiesIndicates all abilities in the current module. The value is an array of objects, each of which represents an ability.Array of objectsYes (initial value: left empty)
jsIndicates a set of all modules developed using the JavaScript UI framework. Each element in the set represents the information about a JavaScript module.Array of objectsYes (initial value: left empty)
shortcutsIndicates the shortcut information of the application. The value is an array of objects, each of which represents a shortcut object.Array of objectsYes (initial value: left empty)
defPermissionsIndicates the permissions required by the application. The callers must acquire these permissions before calling the application.Array of objectsYes (initial value: left empty)
reqPermissionsIndicates the permissions that the application applies for from the system before its running.Array of objectsYes (initial value: left empty)
colorModeIndicates the color mode of the application.dark: Resources applicable for the dark mode are selected.light: Resources applicable for the light mode are selected.auto: Resources are selected based on the color mode of the system.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringYes (initial value: auto)
resizeableIndicates whether the application supports the multi-window feature.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.BooleanYes (initial value: true)
distroFilterIndicates the application distribution rules.This attribute defines the rules for distributing HAPs based on different device specifications, so that precise matching can be performed when HUAWEI AppGallery distributes applications.Apps can be distributed by API version, screen shape, or screen resolution. During distribution, a unique HAP is determined based on the mapping between deviceType and these three factors.Array of objectsYes (initial value: left empty) Configure this attribute when an application has multiple entry modules.

Example of the module tag structure:

"module": {    "mainAbility": "MainAbility",    "package": "com.example.myapplication.entry",     "name": ".MyOHOSAbilityPackage",     "description": "$string:description_application",     "supportedModes": [        "drive"    ],     "deviceType": [        "car"    ],     "distro": {        "deliveryWithInstall": true,         "moduleName": "ohos_entry",         "moduleType": "entry"    },     "abilities": [        ...    ],     "shortcuts": [        ...    ],    "js": [        ...    ],     "reqPermissions": [        ...    ],     "defPermissions": [        ...    ],    "colorMode": "light"}

AttributeDescriptionData TypeInitial Value Allowed
deliveryWithInstallSpecifies whether the HAP file is installed when the user installs the application.true: The HAP file is installed during the application installation.false: The HAP file is not installed during the application installation.NOTEIt is recommended that you set this attribute to true.If it is set to false, an error may occur when the application is released to the application market.BooleanNo
moduleNameIndicates the name of the current HAP file.StringNo
moduleTypeIndicates the type of the current HAP file. The value can be entry or feature.StringNo
installationFreeIndicates whether the HAP file supports the installation-free feature.true: The HAP file supports the installation-free feature and meets installation-free constraints.false: The HAP file does not support the installation-free feature.Pay attention to the following:When entry.hap is set to true, all feature.hap fields related to entry.hap must be true.When entry.hap is set to falsefeature.hap related to entry.hap can be set to true or false based on service requirements.BooleanNo

Example of the distro attribute structure:

"distro": {    "deliveryWithInstall": true,     "moduleName": "ohos_entry",     "moduleType": "entry",    "installationFree": true} 

AttributeSub-attributeDescriptionData TypeInitial Value Allowed
parametersIndicates the metadata of the parameters to be passed for calling the ability. The metadata of each parameter consists of the descriptionname, and type sub-attributes.ObjectYes (initial value: left empty)
descriptionDescribes the parameter. The value can be a string or a resource index to descriptions in multiple languages.StringYes (initial value: left empty)
nameIndicates the name of the parameter.StringYes (initial value: left empty)
typeIndicates the type of the parameter, for example, Integer.StringNo
resultsIndicates the metadata of the ability return value. The metadata of each return value consists of the descriptionname, and type sub-attributes.ObjectYes (initial value: left empty)
descriptionDescribes the return value. The value can be a string or a resource index to descriptions in multiple languages.StringYes (initial value: left empty)
nameIndicates the name of the return value.StringYes (initial value: left empty)
typeIndicates the type of the return value, for example, Integer.StringNo
customizeDataIndicates the custom metadata of the parent component. The parameters and results attributes are not configurable in the module tag.ObjectYes (initial value: left empty)
nameIndicates the key of a data element. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)
valueIndicates the value of a data element. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)
extraIndicates the custom format of the data element. The value is an index to the resource that identifies the data.StringYes (initial value: left empty)

Example of the metaData attribute structure:

"metaData": {    "parameters" : [{        "name" : "string",        "type" : "Float",        "description" : "$string:parameters_description"    }],    "results" : [{        "name" : "string",        "type" : "Float",        "description" : "$string:results_description"    }],    "customizeData" : [{        "name" : "string",        "value" : "string",        "extra" : "$string:customizeData_description"    }]}

AttributeDescriptionData TypeInitial Value Allowed
nameIndicates the name of the ability. The value is a reverse domain name, in the format of “Bundle name.Class name”, for example, “com.example.myapplication.MainAbility”. Alternatively, the value can start with a period (.) followed by the class name, for example, “.MainAbility”.The ability name must be unique in an application.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.NOTEWhen you use DevEco Studio to create a project, the configuration of the first ability is generated by default, including the MainAbility.java file and the class name MainAbility defaulted in the name string for the abilities attribute in config.json. The value of this attribute can be customized if you use other IDE tools.StringNo
descriptionDescribes the ability. The value can be a string or a resource index to descriptions in multiple languages.StringYes (initial value: left empty)
iconIndicates the index to the ability icon file, for example, $media:ability_icon.In the skills attribute of the ability, if the actions value contains action.system.home and the entities value contains entity.system.home, the icon of the ability is also used as the icon of the application. If multiple abilities address this condition, the icon of the first candidate ability is used as the application icon.NOTEThe icon and label values of an app are visible to users. Ensure that at least one of them is different from any existing icons or labels.StringYes (initial value: left empty)
labelIndicates the ability name visible to users. The value can be a name string or a resource index to names in multiple languages.In the skills attribute of the ability, if the actions value contains action.system.home and the entities value contains entity.system.home, the label of the ability is also used as the label of the application. If multiple abilities address this condition, the label of the first candidate ability is used as the application label.NOTEThe icon and label values of an app are visible to users. Ensure that at least one of them is different from any existing icons or labels.StringYes (initial value: left empty)
uriIndicates the Uniform Resource Identifier (URI) of the ability, in the format of “[scheme:][//authority][path][?query][#fragment]”.StringYes (No for abilities using the Data template)
launchTypeIndicates the startup type of the ability. The value can be standardsingleMission, or singleton.standard: Multiple Ability instances can be created during startup. Most abilities can use this type.singleMission: Only a single Ability instance can be created in each task stack during startup.singleton: Only a single Ability instance can be created across all task stacks during startup. For example, a globally unique incoming call screen uses the singleton startup type.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringYes (initial value: standard)
visibleSpecifies whether the ability can be called by other applications.true: The ability can be called by other applications.false: The ability cannot be called by other applications.BooleanYes (initial value: false)
permissionsIndicates the permissions required for abilities of another application to call the current ability, generally in the format of a reverse domain name. The value can be either the permissions predefined in the OS or your custom permissions. If a custom permission is used, the value must be the same as the name value of a specific permission defined in the defPermissions attribute.Array of stringsYes (initial value: left empty)
skillsIndicates the types of the intent that can be accepted by the ability.Array of objectsYes (initial value: left empty)
deviceCapabilityIndicates the device capabilities required to run the ability.Array of stringsYes (initial value: left empty)
metaDataIndicates the metadata of the ability.Metadata of the parameters to be passed for calling the ability, for example, the number and type of the parameters.Metadata of the return value after the ability is executed, for example, the number and type of the return values.This attribute applies only to smart TVs, wearables, and head units.ObjectYes (initial value: left empty)
typeIndicates the type of the ability. The value can be:page: FA developed using the Page template to provide the capability of interacting with users.service: PA developed using the Service template to provide the capability of running tasks in the background.data: PA developed using the Data template to provide unified data access for external systems.CA: ability that can be started by other apps as a window.StringNo
orientationIndicates the display orientation of the ability. This attribute applies only to the ability using the Page template. The value can be:unspecified: indicates that the system automatically determines the display orientation of the ability.landscape: indicates the landscape orientation.portrait: indicates the portrait orientation.followRecent: indicates that the orientation follows the most recent application in the stack.StringYes (initial value: unspecified)
backgroundModesIndicates the background service type of the ability. You can assign multiple background service types to a specific ability. This attribute applies only to the ability using the Service template. The value can be:dataTransfer: service for downloading, backing up, sharing, or transferring data from the network or peer devicesaudioPlayback: audio playback serviceaudioRecording: audio recording servicepictureInPicture: picture in picture (PiP) and small-window video playback servicesvoip: voice/video call and VoIP serviceslocation: location and navigation servicesbluetoothInteraction: Bluetooth scanning, connection, and transmission serviceswifiInteraction: WLAN scanning, connection, and transmission servicesscreenFetch: screen recording and screenshot servicesmultiDeviceConnection: multi-device interconnection serviceArray of stringsYes (initial value: left empty)
readPermissionIndicates the permission required for reading ability data. This attribute applies only to the ability using the Data template. The value is a string with a maximum of 255 bytes.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringYes (initial value: left empty)
writePermissionIndicates the permission required for writing data to the ability. This attribute applies only to the ability using the Data template. The value is a string with a maximum of 255 bytes.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringYes (initial value: left empty)
configChangesIndicates the system configurations that the ability concerns. Upon any changes on the concerned configurations, the onConfigurationUpdated callback will be invoked to notify the ability. The value can be:mcc: indicates that the mobile country code (MCC) of the IMSI is changed.Typical scenario: A SIM card is detected, and the MCC is updated.mnc: indicates that the mobile network code (MNC) of the IMSI is changed.Typical scenario: A SIM card is detected, and the MNC is updated.locale: indicates that the locale is changed.Typical scenario: The user has selected a new language for the text display of the device.layout: indicates that the screen layout is changed.Typical scenario: Currently, different display forms are all in the active state.fontSize: indicates that font size is changed.Typical scenario: A new global font size is set.orientation: indicates that the screen orientation is changed.Typical scenario: The user rotates the device.density: indicates that the display density is changed.Typical scenario: The user may specify different display ratios, or different display forms are active at the same time.size: indicates that the size of the display window is changed.smallestSize: indicates that the length of the shorter side of the display window is changed.colorMode: indicates that the color mode is changed.Array of stringsYes (initial value: left empty)
missionIndicates the task stack of the ability. This attribute applies only to the ability using the Page template. By default, all abilities in an application belong to the same task stack.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringYes (initial value: bundle name of the application)
targetAbilityIndicates the target ability that this ability alias points to. This attribute applies only to the ability using the Page template. If the targetAbility attribute is configured, only the name, icon, label, visible, permissions, and skills attribute settings of this ability alias take effect. Other attributes use the values in the targetAbility attribute. The target ability must belong to the same application as the alias and must be declared in config.json ahead of the alias.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.StringYes (initial value: left empty, indicating that the current ability is not an alias)
multiUserSharedSpecifies whether the ability supports data sharing among multiple users. This attribute applies only to the ability using the Data template.If this attribute is set to true, only one copy of data is stored for multiple users. Note that this attribute will invalidate the visible attribute.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.BooleanYes (initial value: false)
supportPipModeSpecifies whether the ability allows the user to enter the Picture in Picture (PiP) mode. The PiP mode enables the user to watch a video in a small window that hovers on top of a full screen window (main window). This attribute applies only to the ability using the Page template.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.BooleanYes (initial value: false)
formsEnabledSpecifies whether the ability supports forms. This attribute applies only to the ability using the Page template.true: This ability can provide forms.false: This ability cannot provide forms.BooleanYes (initial value: false)
formsIndicates details about the forms used by the ability. This attribute is valid only when formsEnabled is set to true.Array of objectsYes (initial value: left empty)
resizeableIndicates whether the ability supports the multi-window feature.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.BooleanYes (initial value: true)

Example of the abilities attribute structure:

"abilities": [    {        "name": ".MainAbility",        "description": "himusic main ability",        "icon": "$media:ic_launcher",        "label": "HiMusic",        "launchType": "standard",        "orientation": "unspecified",        "permissions": [        ],         "visible": true,        "skills": [            {                "actions": [                    "action.system.home"                ],                "entities": [                    "entity.system.home"                ]            }        ],        "configChanges": [            "locale",             "layout",             "fontSize",             "orientation"        ],         "type": "page"    },    {        "name": ".PlayService",        "description": "himusic play ability",        "icon": "$media:ic_launcher",        "label": "HiMusic",        "launchType": "standard",        "orientation": "unspecified",        "visible": false,        "skills": [            {                "actions": [                    "action.play.music",                    "action.stop.music"                ],                "entities": [                    "entity.audio"                ]            }        ],        "type": "service",        "backgroundModes": [            "audioPlayback"        ]    },    {        "name": ".UserADataAbility",        "type": "data",        "uri": "dataability://com.huawei.hiworld.himusic.UserADataAbility",        "visible": true    }]

AttributeSub-attributeDescriptionData TypeInitial Value Allowed
actionsIndicates the actions of the intent that can be accepted by the ability.The value can have one or multiple actions predefined in the system. For details, see the ohos.aafwk.content.Intent class in the API Reference.Array of stringsYes (initial value: left empty)
entitiesIndicates the entities of the intent that can be accepted by the ability, such as video and Home application.The value can have one or multiple entities predefined in the system. For details, see the ohos.aafwk.content.Intent class in the API Reference.Array of stringsYes (initial value: left empty)
urisIndicates the URIs of the intent that can be accepted by the ability.Array of objectsYes (initial value: left empty)
schemeIndicates the scheme in the URI.StringNo
hostIndicates the host in the URI.StringYes (initial value: left empty)
portIndicates the port number in the URI.StringYes (initial value: left empty)
pathIndicates the path in the URI.StringYes (initial value: left empty)
typeIndicates the type of the URI.StringYes (initial value: left empty)

Example of the skills attribute structure:

"skills": [    {        "actions": [            "action.system.home"        ],         "entities": [            "entity.system.home"        ],        "uris": [            {                 "scheme": "http",                 "host": "www.xxx.com",                 "port": "8080",                 "path": "query/student/name",                 "type": "text/*"             }         ]    }]

AttributeSub-attributeDescriptionData TypeInitial Value Allowed
nameIndicates the name of the JavaScript component. The default value is default.StringNo
pagesDescribes the route information about all pages in the JavaScript component, including the page path and page name. The value is an array, in which each element represents a page. The first element in the array represents the home page of the JavaScript FA.ArrayNo
windowDefines window-related configurations.This attribute applies only to smartphones, tablets, smart TVs, head units, and wearables.ObjectYes
designWidthIndicates the baseline width for page design, in pixels. The size of an element is scaled by the actual device width.NumberYes (initial value: 750px)
autoDesignWidthSpecifies whether to automatically calculate the baseline width for page design. If it is set to true, the designWidth attribute becomes invalid. The baseline width is calculated based on the device width and screen density.BooleanYes (initial value: false)
typeIndicates the type of the JavaScript component. The value can be:normal: indicates that the JavaScript component is an application instance.form: indicates that the JavaScript component is a form instance.StringYes (initial value: normal)

Example of the js attribute structure:

"js": [    {        "name": "default",         "pages": [                        "pages/index/index",            "pages/detail/detail"        ],                 "window": {            "designWidth": 750,            "autoDesignWidth": false        },        "type": "form"    }]

AttributeSub-attributeDescriptionData TypeInitial Value Allowed
shortcutIdIdentifies a shortcut. The value is a string with a maximum of 63 bytes.StringNo
labelIndicates the label of the shortcut, that is, the text description displayed by the shortcut. The value can be a string or a resource index to the description, with a maximum of 63 bytes.StringYes (initial value: left empty)
intentsIndicates the intents to which the shortcut points. The attribute consists of the targetClass and targetBundle sub-attributes.Array of objectsYes (initial value: left empty)
targetClassIndicates the class name for the target ability of the shortcut.StringYes (initial value: left empty)
targetBundleIndicates the application bundle name for the target ability of the shortcut.StringYes (initial value: left empty)

Example of the shortcuts attribute structure:

"shortcuts": [    {        "shortcutId": "id",        "label": "$string:shortcut",        "intents": [            {                "targetBundle": "com.huawei.hiworld.himusic",                "targetClass": "com.huawei.hiworld.himusic.entry.MainAbility"            }        ]    }]

AttributeSub-attributeDescriptionData TypeInitial Value Allowed
nameIndicates the class name of the form. The value is a string with a maximum of 127 bytes.StringNo
descriptionDescribes the form. The value can be a string or a resource index to descriptions in multiple languages, with a maximum of 255 bytes.StringYes (initial value: left empty)
isDefaultSpecifies whether the form is a default one. Each ability has only one default form.true: The form is the default one.false: The form is not the default one.BooleanNo
typeIndicates the type of the form. The value can be:Java: indicates a Java-programmed form.JS: indicates a JavaScript-programmed form.StringNo
colorModeIndicates the color mode of the form. The value can be:auto: The form adopts the auto-adaptive color mode.dark: The form adopts the dark color mode.light: The form adopts the light color mode.StringYes (initial value: auto)
supportDimensionsIndicates the grid styles supported by the form. The value can be:1*2: indicates a grid with one row and two columns.2*2: indicates a grid with two rows and two columns.2*4: indicates a grid with two rows and four columns.4*4: indicates a grid with four rows and four columns.Array of stringsNo
defaultDimensionIndicates the default grid style of the form. The value must be available in the supportDimensions array of the form.StringNo
landscapeLayoutsIndicates the landscape layouts for the grid styles. Values in this array must correspond to the values in the supportDimensions array.This attribute is required only by Java-programmed forms.Array of stringsNo
portraitLayoutsIndicates the portrait layouts for the grid styles. Values in this array must correspond to the values in the supportDimensions array.This attribute is required only by Java-programmed forms.Array of stringsNo
updateEnabledSpecifies whether the form can be updated periodically. The value can be:true: The form can be updated periodically, depending on the update way you select, either at a specified interval (updateDuration) or at the scheduled time (scheduledUpdateTime). updateDuration is preferentially recommended.false: The form cannot be updated periodically.BooleanNo
scheduledUpdateTimeIndicates the scheduled time to update the form. The value is in 24-hour format and accurate to minute.StringYes (initial value: 0:0)
updateDurationIndicates the interval to update the form. The value is a natural number, in the unit of 30 minutes.If the value is 0, this attribute does not take effect.If the value is a positive integer N, the interval is calculated by multiplying N and 30 minutes.NumberYes (initial value: 0)
formConfigAbilityIndicates the deep link to a specific page of the application. The value is a URI.StringYes (initial value: left empty)
jsComponentNameIndicates the component name of a JavaScript-programmed form. The value is a string with a maximum of 127 bytes.This attribute is required only by JavaScript-programmed forms.StringNo
metaDataIndicates the metadata of the form. This attribute contains the array of the customizeData attribute.ObjectYes (initial value: left empty)
customizeDataIndicates the custom information about the form.Array of objectsYes (initial value: left empty)
nameIndicates the name in the custom name-value pair. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)
valueIndicates the value in the custom name-value pair. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)

Example of the forms attribute structure:

"forms": [    {        "name": "Form_Js",        "description": "It's Js Form",        "type": "JS",        "jsComponentName": "card",        "colorMode": "auto",        "isDefault": true,        "updateEnabled": true,        "scheduledUpdateTime": "11:00",        "updateDuration": 1,        "defaultDimension": "2*2",        "supportDimensions": [            "2*2",            "2*4",            "4*4"        ]    },    {        "name": "Form_Java",        "description": "It's Java Form",        "type": "Java",        "colorMode": "auto",        "isDefault": false,        "updateEnabled": true,        "scheduledUpdateTime": "21:05",        "updateDuration": 1,        "defaultDimension": "1*2",        "supportDimensions": [            "1*2"        ],        "landscapeLayouts": [            "$layout:ability_form"        ],        "portraitLayouts": [            "$layout:ability_form"        ],        "formConfigAbility": "ability://com.example.myapplication.fa/.MainAbility",        "metaData": {            "customizeData": [                {                    "name": "originWidgetName",                    "value": "com.huawei.weather.testWidget"                }            ]        }    }]

AttributeSub-attributeDescriptionData TypeInitial Value Allowed
apiVersionIndicates the supported API versions.Array of objectsOptional
policyIndicates whether the value of the sub-attribute is in the trustlist or blocklist. It can be exclude or include. The value include indicates that the value of the sub-attribute is in the trustlist. An attribute is matched if its value matches an enumerated value of value.String
valueThe value can be an integer of the existing API version, for example, 45, or 6.Example: If an app uses two software versions developed using API 5 and API 6 for the same device model, two installation packages of the entry type can be released.Array
screenShapeIndicates the supported screen shapes.Array of objectsOptional
policyIndicates whether the value of the sub-attribute is in the trustlist or blocklist. It can be exclude or include. The value include indicates that the value of the sub-attribute is in the trustlist. An attribute is matched if its value matches an enumerated value of value.String
valueThe value can be circle or rect.Example: Different HAPs can be provided for a smart watch with a circular face and that with a rectangular face.Array of strings
screenWindowIndicates the supported window resolutions when the application is running.This attribute applies only to the lite wearables.Array of objectsOptional
policyIndicates whether the value of the sub-attribute is in the trustlist or blocklist. It can be exclude or include. The value include indicates that the value of the sub-attribute is in the trustlist. An attribute is matched if its value matches an enumerated value of value.The attribute must be set to include, that is, a value in the trustlist is supported.String
valueThe value of a single string is in the format of Width x Height in pixel, for example, 454*454.Array of strings

distroFilter example:

"distroFilter": [    {        "apiVersion": {            "policy": "include",            "value": "4,5"        },        "screenShape": {            "policy": "include",            "value": ["circle","rect"]        },        "screenWindow": {            "policy": "include",            "value": ["454*454","466*466"]        }    }]

Merging the Configuration Files in HAP and HAR

If an application module invokes HAR files, you will need to merge the config.json file contained in the HAP file with those provided by the invoked HAR files into one config.json file during HAP compilation and building. During the merge, the values of the same attribute in different files may conflict. If such a conflict occurs, you can configure mergeRule to resolve it.

Configuration File Merging Rules

The basic merging rule is that all configuration information in the HAR file must be merged into config.json of the HAP file. For details, see Table 16.A HAP file always enjoys a higher priority than a HAR file. If the HAP file depends on multiple HAR files, the HAR file that is loaded earlier has a higher priority than the one that is loaded later. In this case, the config.json files of these HAR files are merged into the HAP file based on the loading sequence of the HAR files.

SNHAP FileHAR FileMerging Rule
1The attribute does not have a value assigned.The attribute does not have a value assigned.The attribute does not have a value assigned.
2The attribute value is A.The attribute does not have a value assigned.The attribute value is A.
3The attribute does not have a value assigned.The attribute value is B.The attribute value is B.
4The attribute value is A.The attribute value is A.The attribute value is A.
5The attribute value is A.The attribute value is B.Add mergeRule to resolve the conflict. For details, see Usage of the mergeRule Attribute.

Usage of the mergeRule Attribute

The mergeRule attribute is generally used in the config.json file of a HAP file and can be added to attributes such as abilities, defPermissions, reqPermissions, and js. For details about the merging rules for different attributes, see Table 17.NOTICE

  • The config.json file in a HAR file cannot contain the action.system.home and entity.system.home configuration items. Otherwise, an error may occur during compilation.
  • The name value in the abilities attribute must be a complete class name. Otherwise, an error may occur during the merge.

AttributeMerging Rule
Level 1Level 2Level 3
appRetain only the app attribute in the config.json file of the HAP file.
deviceConfigRetain only the deviceConfig attribute in the config.json file of the HAP file.
modulepackageRetain only the attribute value in the config.json file of the HAP file.
nameRetain only the attribute value in the config.json file of the HAP file.
descriptionRetain only the attribute value in the config.json file of the HAP file.
supportedModesRetain only the attribute value in the config.json file of the HAP file.
deviceTypeRetain only the attribute value in the config.json file of the HAP file.
distroRetain only the attribute value in the config.json file of the HAP file.
shortcutsRetain only the attribute value in the config.json file of the HAP file.
defPermissionsIf the name values in the module tags are different, use the union set of the config.json files of the HAP and HAR files.If the name values in the module tags are the same, add mergeRule to the conflicting attribute in the config.json file of the HAP file to resolve the merge conflict.
reqPermissionsIf the name values in the module tags are different, use the union set of the config.json files of the HAP and HAR files.If the name values in the module tags are the same, add mergeRule to the conflicting attribute in the config.json file of the HAP file to resolve the merge conflict.
jsIf the name values in the module tags are different, use the union set of the config.json files of the HAP and HAR files.If the name values in the module tags are the same, add mergeRule to the conflicting attribute in the config.json file of the HAP file to resolve the merge conflict.
abilitiesIf the name values in the module tags are different, use the union set of the config.json files of the HAP and HAR files.If the name values in the module tags are the same, add mergeRule to the conflicting attribute in the config.json file of the HAP file to resolve the merge conflict.
permissionsUse the union set of the config.json files of the HAP and HAR files.
skillsUse the union set of the config.json files of the HAP and HAR files.
backgroundModesUse the union set of the config.json files of the HAP and HAR files.
configChangesUse the union set of the config.json files of the HAP and HAR files.
targetAbilityIf the targetAbility value conflicts with the name value in the abilities attribute, a compilation error occurs.
OthersIf a merge conflict occurs for other sub-attributes in the abilities attribute, add the mergeRule attribute to resolve the conflict.
AttributeDescriptionData TypeInitial Value Allowed
removeIndicates the attribute to be removed during the merge of the config.json files.Array of stringsYes
replaceIndicates the attribute to be replaced when a conflict occurs during the merge of the config.json files. The attribute value of the file with a higher priority is always retained.Array of stringsYes

Example of using the mergeRule attribute:

In this example, the HAP file and HAR file have the same name value in the abilities attributes, and therefore the abilities attributes in the two config.json files need to be merged. Some sub-attributes, for example, launchType, conflict between the two config.json files. Therefore, you need to add mergeRule under the abilities attribute of the HAP file.

  1. The config.json file of the HAP file before the merge is as follows:remove indicates the sub-attribute to be removed in the merge, and replace indicates the sub-attribute to be replaced (the one in the HAP file replaces the one in the HAR file).
    1. “abilities”: [
    2. {
    3. “mergeRule”: {
    4. “remove”: [“orientation”],
    5. “replace”: [“launchType”]
    6. }
    7. “name”: “com.harmony.myapplication.entry.MainAbility”,
    8. “type”: “page”,
    9. “launchType”: “standard”,
    10. “visible”: false
    11. }
    12. ],
  2. The config.json file of the HAR file before the merge is as follows:
    1. “abilities”: [
    2. {
    3. “name”: “com.harmony.myapplication.entry.MainAbility”,
    4. “type”: “page”,
    5. “launchType”: “singleton”,
    6. “orientation”: “portrait”,
    7. “visible”: false
    8. }
    9. ],
  3. Merge the two config.json files based on mergeRule, which will be removed after the merge is complete. The config.json file after the merge is as follows:
    1. “abilities”: [
    2. {
    3. “name”: “com.harmony.myapplication.entry.MainAbility”,
    4. “type”: “page”,
    5. “launchType”: “standard”,
    6. “visible”: false
    7. }
    8. ],

Usage of the bundleName Placeholder

The bundle name is required in multiple scenarios in the config.json file of a HAR file, for example, customizing permissions and actions. However, the bundle name can be determined only after the HAR file is compiled to a HAP file. Therefore, the {bundleName} placeholder can be used in the HAR files to represent the bundle name before the compilation.

The following attributes support the bundleName placeholder: actionsentitiespermissionsreadPermissionwritePermission, and defPermissions.name.

Example of using the bundleName placeholder:

  1. Use {bundleName} in the actions attribute to represent the bundle name when customizing actions in the HAR file:
    1. “skills”: [
    2. {
    3. “actions”: [
    4. “{bundleName}.ACTION_PLAY”
    5. ],
    6. “entities”: [
    7. “{bundleName}.ENTITY_PLAY”
    8. ],
    9. }
    10. ],
  2. After compilation into the HAP file, {bundleName} is replaced with com.huawei.hiworld, the real bundle name used by the HAP file:
    1. “app”: {
    2. “bundleName”: “com.huawei.hiworld”,
    3. ……
    4. },
    5. “module”: {
    6. “abilities”: [
    7. {
    8. “skills”: [
    9. {
    10. “actions”: [
    11. “com.huawei.hiworld.ACTION_PLAY”
    12. ],
    13. “entities”: [
    14. “com.huawei.hiworld.ENTITY_PLAY”
    15. ],
    16. }
    17. ],

source : https://developer.harmonyos.com/en/docs/documentation/doc-guides/basic-config-file-elements-0000000000034463