harmony(鸿蒙)Application Package Structure Configuration File

2022-08-09 浏览 (955)

Application Package Structure Configuration File

When developing an application in the Feature Ability (FA) model, you must declare the package structure of the application in the config.json file.

Internal Structure of the config.json File

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

Table 1 Internal structure of the config.json file

TagDescriptionData TypeInitial Value Allowed
appGlobal configuration of the application. Different HAP files of the same application must use the same app configuration. For details, see Internal Structure of the app Tag.ObjectNo
deviceConfigApplication configuration applied to a specific type of device. For details, see Internal Structure of the deviceconfig Tag.ObjectNo
moduleConfiguration of a HAP file. It is valid only for the current HAP file. For details, see Internal Structure of the module Tag.ObjectNo

Example of the config.json file:

{
  "app": {
    "bundleName": "com.example.myapplication",
    "vendor": "example",
    "version": {
      "code": 1,
      "name": "1.0"
    },
    "apiVersion": {
      "compatible": 4,
      "target": 5,
      "releaseType": "Beta1"
    }
  },
  "deviceConfig": {},
  "module": {
    "package": "com.example.myapplication.entrymodule",
    "name": ".MyApplication",
    "deviceType": [
      "default"
    ],
    "distro": {
      "moduleName": "entry",
      "moduleType": "entry"
    },
    "abilities": [
      {
        "skills": [
          {
            "entities": [
              "entity.system.home"
            ],
            "actions": [
              "action.system.home"
            ]
          }
        ],
        "name": "com.example.myapplication.entrymodule.MainAbility",
        "icon": "$media:icon",
        "description": "$string:mainability_description",
        "label": "$string:app_name",
        "type": "page",
        "launchType": "standard"
      }
    ],
    "js": [
      {
        "pages": [
          "pages/index/index"
        ],
        "name": "default",
        "window": {
          "designWidth": 720,
          "autoDesignWidth": false
        }
      }
    ]
  }
}

Internal Structure of the app Tag

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

Table 2 Internal structure of the app tag

AttributeDescriptionData TypeInitial Value Allowed
bundleNameBundle name, which uniquely identifies an 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.example.myapplication. It is recommended that the first level be the domain suffix "com" and the second level be the vendor/individual name. More levels are also accepted.StringNo
vendorDescription of the application vendor. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)
versionVersion of the application. For details, see Table 3.ObjectNo
apiVersionOpenHarmony API version on which the application depends. For details, see Table 4.ObjectYes (initial value: left empty)
singletonWhether to enable singleton mode for the application. This attribute applies only to system applications and does not take effect for third-party applications. If this attribute is set to true, the application always runs in singleton mode, even in multi-user scenarios. This attribute is supported since API version 8.BooleanYes (initial value: false)
removableWhether the application can be uninstalled. This attribute applies only to system applications and does not take effect for third-party applications. It is supported since API version 8.BooleanYes (initial value: true)
userDataClearableWhether user data of the application can be cleared. This attribute applies only to system applications and does not take effect for third-party applications. It is supported since API version 8.BooleanYes (initial value: true)

Table 3 Internal structure of version

AttributeDescriptionData TypeInitial Value Allowed
nameApplication version number visible to users. The value can be customized and cannot exceed 127 bytes. The customization rules are as follows:
API 5 and earlier versions: A three-segment version number is recommended, for example, A.B.C (also compatible with A.B). In the version number, A, B, 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, A, B, 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.
NumberNo
codeApplication version number used only for application management by OpenHarmony. 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: The conversion rules are as follows:
Value of code = A * 1,000,000 + B * 1,000 + C. For example, if the value of version.name is 2.2.1, the value of code is 2002001.
API 6 and later versions: The value of code is not associated with the value of version.name and can be customized. The value is a non-negative integer ranging from 2 to 31. Note that the value must be updated each time the application version is updated. The value for a later version must be greater than that for an earlier version.
NumberNo
minCompatibleVersionCodeEarliest version compatible with the application. It is used in the cross-device scenario to check whether the application is compatible with a specific version on other devices.
The value rules are the same as those of version.code.
NumberNo (initial value: code attribute value)

Table 4 Internal structure of apiVersion

AttributeDescriptionData TypeInitial Value Allowed
compatibleMinimum API version required for running the application. The value ranges from 0 to 2147483647.IntegerYes
targetTarget API version required for running the application. The value ranges from 0 to 2147483647.IntegerYes
releaseTypeType of the target API version required for running the application.StringYes

Example of the app tag structure:

"app": {
    "bundleName": "com.example.myapplication",
    "vendor": "example",
    "version": {
        "code": 1,
        "name": "1.0"
    },
    "apiVersion": {
        "compatible": 4,
        "target": 5,
        "releaseType": "Beta1"
    }
}

Internal Structure of the deviceConfig Tag

The deviceConfig tag contains the application configuration information on the device, including attributes such as default, tv, car, and wearable. 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 5.

Table 5 Internal structure of the deviceConfig tag

AttributeDescriptionData TypeInitial Value Allowed
defaultApplication configuration applied to all types of devices. For details, see Table 6.ObjectNo
tabletApplication configuration specific to tablets. For details, see Table 6.ObjectYes (initial value: left empty)
tvApplication configuration specific to smart TVs. For details, see Table 6.ObjectYes (initial value: left empty)
carApplication configuration specific to head units. For details, see Table 6.ObjectYes (initial value: left empty)
wearableApplication configuration specific to wearables. For details, see Table 6.ObjectYes (initial value: left empty)

For details about the internal structures of device attributes, see Table 6.

Table 6 Internal structure of device attributes

AttributeDescriptionData TypeInitial Value Allowed
processProcess 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 the default, tablet, smart TV, head unit, and wearable device types. The value can contain a maximum of 31 characters.StringYes
keepAliveWhether the application is always kept alive. This attribute applies only to system applications and does not take effect for third-party applications. The value true means that the application is always kept alive: The system automatically launches the application at startup and restarts it after it exits.BooleanYes (initial value: false)
supportBackupWhether the application supports backup and restoration. The value false means that the application does not support backup or restoration.
This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.
BooleanYes (initial value: false)
compressNativeLibsWhether the libs libraries are packaged in the HAP file after being compressed. The value false means that 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 the default, tablet, smart TV, head unit, and wearable device types.
BooleanYes (initial value: true)
directLaunchWhether the application can be started when the device is locked. The value true means that the application can be started when the device is locked. Devices running OpenHarmony do not support this attribute.BooleanYes (initial value: false)
arkMaple configuration. For details, see Table 7.ObjectYes (initial value: left empty)
networkNetwork 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. For details, see Table 9.ObjectYes (initial value: left empty)

Table 7 Internal structure of the ark attribute

AttributeDescriptionData TypeInitial Value Allowed
reqVersionMaple version required for the application. For details, see Table 8.ObjectNo
flagType of the Maple application.StringNo (available options: m, mo, z).

Table 8 Internal structure of the reqVersion attribute

AttributeDescriptionData TypeInitial Value Allowed
compatibleMinimum Maple version required for the application. The value is a 32-bit unsigned integer.IntegerNo
targetType of the Maple application. The value is a 32-bit unsigned integer.IntegerNo

Table 9 Internal structure of the network attribute

AttributeDescriptionData TypeInitial Value Allowed
cleartextTrafficWhether to allow the application to use plaintext 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)
securityConfigNetwork security configuration of the application. For details, see Table 10.ObjectYes (initial value: left empty)

Table 10 Internal structure of the securityConfig attribute

AttributeSub-attributeDescriptionData TypeInitial Value Allowed
domainSettings-Security settings of the custom network domain. This attribute allows nested domains. That is, the domainSettings object of a network domain can be nested with the domainSettings objects of smaller network domains.ObjectYes (initial value: left empty)
cleartextPermittedWhether plaintext traffic can be transmitted in the custom network domain. If both cleartextTraffic and security 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
domainsDomain name. This attribute consists of two sub-attributes: subdomains and name.
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.
Object arrayNo

Example of the deviceConfig tag structure:

"deviceConfig": {
    "default": {
        "process": "com.example.test.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 contains the configuration information of the HAP file. For details about the internal structure, see Table 11.

Table 11 Internal structure of the module tag

AttributeDescriptionData TypeInitial Value Allowed
mainAbilityAbility displayed on the Service Center icon. When the resident process is started, the mainAbility is started.StringNo if any ability using the Page template exists
packagePackage name of the HAP file, which 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 the default, tablet, smart TV, head unit, and wearable device types.StringNo
nameClass name of the HAP file. The value is in the reverse domain name notation, with the prefix same as the package name specified by package at the same level. It can also start with a period (.). The value is a string with a maximum of 255 bytes.
This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.
StringNo
descriptionDescription of the HAP file. The value is a string with a maximum of 255 bytes. If the value exceeds the limit or needs to support multiple languages, you can use a resource index to the description. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.StringYes (initial value: left empty)
supportedModesMode supported by the application. Currently, only the drive mode is defined. This attribute applies only to head units.String arrayYes (initial value: left empty)
deviceTypeType of device on which the ability can run. The device types predefined in the system include tablet, tv, car, and wearable.String arrayNo
distroDistribution description of the HAP file. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types. For details, see Table 12.ObjectNo
metaDataMetadata of the HAP file. For details, see Table 13.ObjectYes (initial value: left empty)
abilitiesAll abilities in the current module. The value is an array of objects, each of which represents a shortcut object. For details, see Table 17.Object arrayYes (initial value: left empty)
jsA set of JS modules developed using ArkUI. Each element in the set represents the information about a JS module. For details, see Table 22.Object arrayYes (initial value: left empty)
shortcutsShortcuts of the application. The value is an array of objects, each of which represents a shortcut object. For details, see Table 25.Object arrayYes (initial value: left empty)
reqPermissionsPermissions that the application requests from the system when it is running. For details, see Table 21.Object arrayYes (initial value: left empty)
colorModeColor mode of the application. Available values are as follows:
"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 the default, tablet, smart TV, head unit, and wearable device types.
StringYes (initial value: auto)
distroFilterDistribution rules of the application.
AppGallery uses these rules to distribute HAP files to the matching devices. Distribution rules cover three factors: API version, screen shape, and screen resolution. AppGallery distributes a HAP file to the device whose on the mapping between deviceType and these three factors. For details, see Table 29.
ObjectYes (initial value: left empty) Set this attribute when an application has multiple entry modules.
reqCapabilitiesDevice capabilities required for running the application.String arrayYes (initial value: left empty)
commonEventsStatic broadcast. For details, see Table 35.Object arrayYes (initial value: left empty)
entryThemeKeyword of an OpenHarmony internal theme. Set it to the resource index of the name.StringYes (initial value: left empty)
testRunnerTest runner configuration. For details, see Table 36.ObjectYes (initial value: left empty)
definePermissionsPermissions defined for the HAP file. This attribute applies only to system applications and does not take effect for third-party applications. The caller of the application must have these permissions to properly call the app. For details, see Table 37.ObjectYes (initial value: left empty)

Example of the module tag structure:

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

Table 12 Internal structure of the distro attribute

AttributeDescriptionData TypeInitial Value Allowed
moduleNameName of the HAP file. The maximum length is 31 characters.StringNo
moduleTypeType of the HAP file. The value can be entry or feature. For the HAR type, set this attribute to har.StringNo
installationFreeWhether 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 false, feature.hap related to entry.hap can be set to true or false based on service requirements.
BooleanNo
deliveryWithInstallWhether the HAP file is installed with application.
true: The HAP file is installed together with the application.
false: The HAP file is not installed together with the application.
BooleanNo

Example of the distro attribute structure:

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

Table 13 Internal structure of the metaData attribute

AttributeDescriptionData TypeInitial Value Allowed
parametersMetadata of the parameters to be passed for calling the ability. The metadata of each parameter consists of the description, name, and type sub-attributes. For details, see Table 14.Object arrayYes (initial value: left empty)
resultsMetadata of the ability return value. The metadata of each return value consists of the description, name, and type sub-attributes. For details, see Table 15.Object arrayYes (initial value: left empty)
customizeDataCustom metadata of the parent component. parameters and results cannot be configured in application. For details, see Table 16.Object arrayYes (initial value: left empty)

Table 14 Internal structure of the parameters attribute

AttributeDescriptionData TypeInitial Value Allowed
descriptionDescription of the parameter passed for calling the ability. The value can be a string or a resource index to descriptions in multiple languages. The value can contain a maximum of 255 characters.StringYes (initial value: left empty)
nameName of the parameter passed for calling the ability. The value can contain a maximum of 255 characters.StringYes (initial value: left empty)
typeType of the parameter passed for calling the ability, for example, Integer.StringNo

Table 15 Internal structure of the results attribute

AttributeDescriptionData TypeInitial Value Allowed
descriptionDescription of the return value. The value can be a string or a resource index to descriptions in multiple languages. The value can contain a maximum of 255 characters.StringYes (initial value: left empty)
nameName of the return value. The value can contain a maximum of 255 characters.StringYes (initial value: left empty)
typeType of the return value, for example, Integer.StringNo

Table 16 Internal structure of the customizeData attribute

AttributeDescriptionData TypeInitial Value Allowed
nameKey of the data item. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)
valueValue of the data item. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)
extraCustom format of the data item. 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"
    }]
}

Table 17 Internal structure of the abilities attribute

AttributeDescriptionData TypeInitial Value Allowed
processName 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. If this attribute is set to the name of the process running other applications, all these applications can run in the same process, provided they have the same unified user ID and the same signature. Devices running OpenHarmony do not support this attribute.StringYes (initial value: left empty)
nameAbility name. The value can be 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 the default, tablet, smart TV, head unit, and wearable device types.
Note: If you use DevEco Studio to create the project, an ability named MainAbility will be created together with the default configuration in the config.json file. The value of this attribute can be customized if you use other IDEs. The value can contain a maximum of 127 characters.
StringNo
descriptionDescription of the ability. The value can be a string or a resource index to descriptions in multiple languages. The value can contain a maximum of 255 characters.StringYes (initial value: left empty)
iconIndex to the ability icon file. Example value: $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.
Note: The icon and label values of an application are visible to users. Ensure that at least one of them is different from any existing icons or labels.
StringYes (initial value: left empty)
labelAbility 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.
Note: The icon and label values of an application are visible to users. Ensure that at least one of them is different from any existing icons or labels. The value can be a reference to a string defined in a resource file or a string enclosed in brackets ({}). The value can contain a maximum of 255 characters.
StringYes (initial value: left empty)
uriUniform Resource Identifier (URI) of the ability. The value can contain a maximum of 255 characters.StringYes (No for abilities using the Data template)
launchTypeLaunch type of the ability. Available values are as follows:
"standard": Multiple Ability instances can be created during startup. Most abilities can use this type.
"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 the default, tablet, smart TV, head unit, and wearable device types.
StringYes (initial value: "singleton")
visibleWhether 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)
permissionsPermissions required for abilities of another application to call the current ability. The value is an array of permission names predefined by the system, generally in the format of a reverse domain name the reverse domain name format (a maximum of 255 bytes).String arrayYes (initial value: left empty)
skillsTypes of the want that can be accepted by the ability.Object arrayYes (initial value: left empty)
deviceCapabilityDevice capabilities required to run the ability.String arrayYes (initial value: left empty)
metaDataMetadata. For details, see Table 13.ObjectYes (initial value: left empty)
typeAbility type. Available values are as follows:
"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 applications as a window.
StringNo
orientationDisplay orientation of the ability. This attribute applies only to the ability using the Page template. Available values are as follows:
"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")
backgroundModesBackground 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. Available values are as follows:
dataTransfer: service for downloading, backing up, sharing, or transferring data from the network or peer devices
audioPlayback: audio playback service
audioRecording: audio recording service
pictureInPicture: picture in picture (PiP) and small-window video playback services
voip: voice/video call and VoIP services
location: location and navigation services
bluetoothInteraction: Bluetooth scanning, connection, and transmission services
wifiInteraction: WLAN scanning, connection, and transmission services
screenFetch: screen recording and screenshot services
multiDeviceConnection: multi-device interconnection service
String arrayYes (initial value: left empty)
grantPermissionWhether permissions can be granted for any data in the ability.BooleanYes (initial value: left empty)
readPermissionPermission required for reading data in 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 the default, tablet, smart TV, head unit, and wearable device types.StringYes (initial value: left empty)
writePermissionPermission 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 the default, tablet, smart TV, head unit, and wearable device types.StringYes (initial value: left empty)
configChangesSystem configurations that the ability concerns. Upon any changes on the concerned configurations, the onConfigurationUpdated callback will be invoked to notify the ability. Available values are as follows:
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.
String arrayYes (initial value: left empty)
missionTask 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 the default, tablet, smart TV, head unit, and wearable device types.StringYes (initial value: bundle name of the application)
targetAbilityTarget ability that this ability alias points to. This attribute applies only to the ability using the Page template. If the targetAbility attribute is set, only name, icon, label, visible, permissions, and skills take effect in the current ability (ability alias). Other attributes use the values of 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 the default, tablet, smart TV, head unit, and wearable device types.StringYes (initial value: left empty, indicating that the current ability is not an alias)
multiUserSharedWhether 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 the default, tablet, smart TV, head unit, and wearable device types.BooleanYes (initial value: false)
supportPipModeWhether 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 the default, tablet, smart TV, head unit, and wearable device types.BooleanYes (initial value: false)
formsEnabledWhether the ability can provide 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)
formsInformation about the forms used by the ability. This attribute is valid only when formsEnabled is set to true. For details, see Table 27.Object arrayYes (initial value: left empty)
srcLanguageProgramming language used to develop the ability. The value can be "js" or "ets".StringYes
srcPathPath of the JS component code corresponding to the ability.StringYes (initial value: left empty)
uriPermissionApplication data that the ability can access. This attribute consists of the mode and path sub-attributes. This attribute is valid only for the capability of the type provider. Devices running OpenHarmony do not support this attribute. For details, see Table 18.ObjectYes (initial value: left empty)
startWindowIconIndex to the icon file of the ability startup page. This attribute applies only to the ability using the Page template. Example: $media:icon.StringYes (initial value: left empty)
startWindowBackgroundIndex to the background color resource file of the ability startup page. This attribute applies only to the ability using the Page template. Example: $color:red.StringYes (initial value: left empty)
removeMissionAfterTerminateWhether to remove the relevant task from the task list after the ability is destroyed. This attribute applies only to the ability using the Page template. The value true means to remove the relevant task from the task list after the ability is destroyed, and false means the opposite.BooleanYes (initial value: false)

Table 18 Internal structure of the uriPermission attribute

AttributeDescriptionData TypeInitial Value Allowed
pathPath identified by uriPermission.StringNo
modeMode matching the uriPermission.StringYes (initial value: default**)

Example of the abilities attribute structure:

"abilities": [
    {
        "name": ".MainAbility",
        "description": "test main ability",
        "icon": "$media:ic_launcher",
        "label": "$media:example",
        "launchType": "standard",
        "orientation": "unspecified",
        "permissions": [], 
        "visible": true,
        "skills": [
            {
                "actions": [
                    "action.system.home"
                ],
                "entities": [
                    "entity.system.home"
                ]
            }
        ],
        "configChanges": [
            "locale", 
            "layout", 
            "fontSize", 
            "orientation"
        ], 
        "type": "page",
        "startWindowIcon": "$media:icon",
        "startWindowBackground": "$color:red",
        "removeMissionAfterTerminate": true
    },
    {
        "name": ".PlayService",
        "description": "example play ability",
        "icon": "$media:ic_launcher",
        "label": "$media:example",
        "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.example.world.test.UserADataAbility",
        "visible": true
    }
]

Table 19 Internal structure of the skills attribute

AttributeDescriptionData TypeInitial Value Allowed
actionsActions of the want that can be accepted by the ability. Generally, the value is an action value predefined in the system.String arrayYes (initial value: left empty)
entitiesEntities of the want that can be accepted by the ability, such as video and home applications.String arrayYes (initial value: left empty)
urisURIs of the want that can be accepted by the ability. For details, see Table 20.Object arrayYes (initial value: left empty)

Table 20 Internal structure of the uris attribute

AttributeDescriptionData TypeInitial Value Allowed
schemeScheme of the URI.StringNo
hostHost value of the URI.StringYes (initial value: left empty)
portPort number of the URI.StringYes (initial value: left empty)
pathStartWithpathStartWith value of the URI.StringYes (initial value: left empty)
pathpath value of the URI.StringYes (initial value: left empty)
pathRegxpathRegx value of the URI.StringYes (initial value: left empty)
typetype value 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.example.com",
                "port": "8080",
                "path": "query/student/name",
                "type": "text/*"
            }
        ]
    }
]

Table 21 reqPermissions

AttributeDescriptionData TypeInitial Value Allowed
nameName of the permission to request.StringNo
reasonReason for requesting the permission. The value cannot exceed 256 bytes. Multi-language adaptation is required.StringNo if the requested permission is user_grant (if it is left empty, application release will be rejected)
usedSceneApplication scenario and timing for using the permission. This attribute consists of the ability and when sub-attributes. ability: ability name. Multiple ability names can be configured. when: time for using the permission. The options are inuse and always.Objectability: mandatory for the user_grant permission and can be left empty in other cases
when: initial value allowed (initial value: inuse)
For details, see Access Control (Permission) Development.

Table 22 Internal structure of the js attribute

AttributeDescriptionData TypeInitial Value Allowed
nameName of the JS component. The default value is default.StringNo
pagesRoute information about all pages in the JS 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
windowWindow-related configurations. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types. For details, see Table 23.ObjectYes
typeType of the JS component. Available values are as follows:
"normal": indicates that the JavaScript component is an application instance.
"form": indicates that the JavaScript component is a widget instance.
StringYes (initial value: "normal")
modeDevelopment mode of the JS component. For details, see Table 24.ObjectYes (initial value: left empty)

Table 23 Internal structure of the window attribute

AttributeDescriptionData TypeInitial Value Allowed
designWidthBaseline width for page design. The size of an element is scaled by the actual device width.NumberYes (initial value: 720px)
autoDesignWidthWhether 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)

Table 24 Internal structure of the mode attribute

AttributeDescriptionData TypeInitial Value Allowed
typeType of the JS component. The value can be "pageAbility" or "form".StringYes (initial value: "pageAbility")
syntaxSyntax type of the JS component. The value can be "hml" or "ets".StringYes (initial value: "hml")

Example of the js attribute structure:

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

Table 25 Internal structure of the shortcuts attribute

AttributeDescriptionData TypeInitial Value Allowed
shortcutIdID of the shortcut. The value is a string with a maximum of 63 bytes.StringNo
labelLabel of the shortcut, that is, the text description displayed for the shortcut. The value can be a string or a resource index to the description. The value is a string with a maximum of 63 bytes.StringYes (initial value: left empty)
iconIcon of the shortcut. The value is a resource index to the description.StringYes (initial value: left empty)
intentsIntents to which the shortcut points. The attribute consists of the targetClass and targetBundle sub-attributes. For details, see Table 26.Object arrayYes (initial value: left empty)

Table 26 Internal structure of the intents attribute

AttributeDescriptionData TypeInitial Value Allowed
targetClassTarget class of the shortcut.StringYes (initial value: left empty)
targetBundleApplication 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.example.world.test",
                "targetClass": "com.example.world.test.entry.MainAbility"
            }
        ]
    }
]

Table 27 Internal structure of the forms attribute

AttributeDescriptionData TypeInitial Value Allowed
nameClass name of the widget. The value is a string with a maximum of 127 bytes.StringNo
descriptionDescription of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)
isDefaultWhether the widget is a default one. Each ability has only one default widget.
true: The widget is the default one.
false: The widget is not the default one.
BooleanNo
typeType of the widget. Available values are as follows:
JS: indicates a JavaScript-programmed widget.
StringNo
colorModeColor mode of the widget. Available values are as follows:
auto: The widget adopts the auto-adaptive color mode.
dark: The widget adopts the dark color mode.
light: The widget adopts the light color mode.
StringYes (initial value: auto)
supportDimensionsGrid styles supported by the widget. Available values are as follows:
1 * 2: indicates a grid with one row and two columns.
2 * 1: indicates a grid with two rows and one column.
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.
String arrayNo
defaultDimensionDefault grid style of the widget. The value must be from the supportDimensions array of the widget.StringNo
updateEnabledWhether the widget can be updated periodically. Available values are as follows:
true: The widget 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 widget cannot be updated periodically.
BooleanNo
scheduledUpdateTimeScheduled time to update the widget. The value is in 24-hour format and accurate to minute.StringYes (initial value: 0:0)
updateDurationInterval to update the widget. The value is a natural number, in the unit of 30 minutes.
If the value is 0, this field 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)
formConfigAbilityName of the facility or activity used to adjust the ability.StringYes (initial value: left empty)
formVisibleNotifyWhether the widget is allowed to use the widget visibility notification.StringYes (initial value: left empty)
jsComponentNameComponent name of the widget. The value is a string with a maximum of 127 bytes. This attribute is required only by JavaScript-programmed widgets.StringNo
metaDataMetadata of the widget. The value contains value of the customizeData attribute. For details, see Table 13.ObjectYes (initial value: left empty)
customizeDataCustom information of the widget. For details, see Table 28.Object arrayYes (initial value: left empty)

Table 28 Internal structure of the customizeData attribute

AttributeDescriptionData TypeInitial Value Allowed
nameKey name that identifies a data item. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)
valueValue of the data item. The value is a string with a maximum of 255 bytes.StringYes (initial value: left empty)
extraCurrent format of the custom data. The value indicates the resource.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_Js",
        "description": "It's JS Form",
        "type": "Js",
        "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.example.weather.testWidget"
                }
            ]
        }
    }
]

Table 29 Internal structure of the distroFilter attribute

AttributeDescriptionData TypeInitial Value Allowed
apiVersionSupported API versions. For details, see Table 30.ObjectYes (initial value: left empty)
screenShapeSupported screen shapes. For details, see Table 31.Object arrayYes (initial value: left empty)
screenWindowSupported window resolutions for when the application is running. This attribute applies only to the lite wearables. For details, see Table 32.Object arrayYes (initial value: left empty)
screenDensityPixel density of the screen, in dots per inch (dpi). For details, see Table 33.Object arrayYes (initial value: left empty)
countryCodeCountry code used for distributing the application. For details, see the ISO-3166-1 standard. Multiple enumerated values of countries and regions are supported. For details, see Table 34.Object arrayYes (initial value: left empty)

Table 30 Internal structure of the apiVersion attribute

AttributeDescriptionData TypeInitial Value Allowed
policyBlocklist and trustlist rule of the sub-attribute value. Set this attribute to exclude or include. include indicates that the sub-attribute value is in the trustlist. If the value matches any of the value enums, it matches this attribute.StringYes (initial value: left empty)
valueAn integer of the existing API version, for example, 4, 5, or 6. Example: If an application 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.ArrayYes (initial value: left empty)

Table 31 Internal structure of the screenShape attribute

AttributeDescriptionData TypeInitial Value Allowed
policyBlocklist and trustlist rule of the sub-attribute value. Set this attribute to exclude or include. include indicates that the sub-attribute value is in the trustlist. If the value matches any of the value enums, it matches this attribute.StringYes (initial value: left empty)
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.ArrayYes (initial value: left empty)

Table 32 Internal structure of the screenWindow attribute

AttributeDescriptionData TypeInitial Value Allowed
policyBlocklist and trustlist rule of the sub-attribute value. Set this attribute to exclude or include. include indicates that the sub-attribute value is in the trustlist. If the value matches any of the value enums, it matches this attribute.StringYes (initial value: left empty)
valueWidth and height of the screen. The value of a single string is in the format of Width x Height in pixels, for example, 454*454.ArrayYes (initial value: left empty)

Table 33 Internal structure of the screenDensity attribute

AttributeDescriptionData TypeInitial Value Allowed
policyBlocklist and trustlist rule of the sub-attribute value. Set this attribute to exclude or include. include indicates that the sub-attribute value is in the trustlist. If the value matches any of the value enums, it matches this attribute.StringYes (initial value: left empty)
valueAvailable values are as follows:
sdpi: screen density with small-scale dots per inch (SDPI). This value is applicable for devices with a DPI range of (0, 120].
mdpi: screen density with medium-scale dots per inch (MDPI). This value is applicable for devices with a DPI range of (120, 160].
ldpi: screen density with large-scale dots per inch (LDPI). This value is applicable for devices with a DPI range of (160, 240].
xldpi: screen density with extra-large-scale dots per inch (XLDPI). This value is applicable for devices with a DPI range of (240, 320].
xxldpi: screen density with extra-extra-large-scale dots per inch (XXLDPI). This value is applicable for devices with a DPI range of (320, 480].
xxxldpi: screen density with extra-extra-extra-large-scale dots per inch (XXXLDPI). This value is applicable for devices with a DPI range of (480, 640].
ArrayYes (initial value: left empty)

Table 34 Internal structure of the countryCode attribute

AttributeDescriptionData TypeInitial Value Allowed
policyBlocklist and trustlist rule of the sub-attribute value. Set this attribute to exclude or include. include indicates that the sub-attribute value is in the trustlist. If the value matches any of the value enums, it matches this attribute.StringYes (initial value: left empty)
valueCountry code of the area to which the application is to be distributed. The value is a string array, of which each substring indicates a country or region. The substring consists of two uppercase letters.String arrayYes (initial value: left empty)

Example of the distroFilter attribute structure:

"distroFilter":  {
    "apiVersion": {
        "policy": "include",
        "value": [4,5]
    },
    "screenShape": {
        "policy": "include",
        "value": ["circle","rect"]
    },
    "screenWindow": {
        "policy": "include",
        "value": ["454*454","466*466"]
    },
    "screenDensity":{
    	"policy": "exclude",
    	"value": ["ldpi","xldpi"]
	},
	"countryCode": {
        "policy":"include",
        "value":["CN","HK"]
    }
}

Table 35 Internal structure of the commonEvents attribute

AttributeDescriptionData TypeInitial Value Allowed
nameName of a static broadcast.StringNo
permissionPermission needed to implement the static common event.String arrayYes (initial value: left empty)
dataAdditional data array to be carried by the current static common event.String arrayYes (initial value: left empty)
typeType array of the current static common event.String arrayYes (initial value: left empty)
eventsA set of events for the wants that can be received. The value can be system predefined or custom.String arrayNo

Example of the commonEvents attribute structure:

"commonEvents": [
    {
        "name":"MainAbility",
        "permission": "string",
        "data":[
            "string",
            "string"
        ],
        "events": [
            "string",
            "string"
        ]
    }
]

Table 36 Internal structure of the testRunner attribute

AttributeDescriptionData TypeInitial Value Allowed
nameName of the test runner object.StringNo
srcPathPath of the test runner code.StringNo
"testRunner": {
    "name": "myTestRUnnerName",
    "srcPath": "etc/test/TestRunner.ts"
}

Table 37 Internal structure of the definePermissions attribute definePermission applies only to system applications and does not take effect for third-party applications.

AttributeDescriptionData TypeInitial Value Allowed
namePermission name.StringNo
grantModePermission grant mode.
Available values are as follows:
"system_grant": The permission is automatically granted by the system after the application is installed.
"user_grant": The permission must be dynamically requested and can be used only after being granted by the user.
StringYes (initial value: "system_grant")
availableLevelPermission level. Available values are as follows:
"system_core": core system permission.
"system_basic": basic system permission.
"normal": normal permission, which is open to all applications.
StringYes (initial value: "normal")
provisionEnableWhether the permission can be requested in provision mode.BooleanYes (initial value: true)
distributedSceneEnabledWhether the permission can be used in distributed scenarios.BooleanYes (initial value: false)
labelBrief description of the permission. The value is a resource index.StringYes
descriptionDetailed description of the permission, which can be a string or a resource index.StringYes

你可能感兴趣的鸿蒙文章

harmony(鸿蒙)Quick Start

harmony(鸿蒙)HarmonyAppProvision Configuration File

harmony(鸿蒙)Basic UI Description

harmony(鸿蒙)Dynamic UI Element Building

harmony(鸿蒙)Getting Started with ArkTS

harmony(鸿蒙)Rendering Control

harmony(鸿蒙)Restrictions and Extensions

harmony(鸿蒙)State Management with Application-level Variables

harmony(鸿蒙)Basic Concepts

harmony(鸿蒙)State Management with Page-level Variables

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/b5f887e4efc84407873f03292e4e9611