“This is the sixth day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

A list,

1.1 structure

There is a “config.json” configuration file in the root directory of each HAP application. The document mainly covers the following three aspects:

Here is the code structure for a simple HarmonyOS application, entry -> SRC -> main -> config.json file. The three modules are app, deviceConfig and Module (the three I show here are the zooming content).

2.1 Editing a View

The config.json file is a JSON file format, and each item contains an attribute and value. The attribute values are not in any order, but cannot be repeated and must be unique. The value is the basic data type of JSON. HarmonyOS ‘DevEco Studio supports two ways to edit config.json: the code edit view and the visual edit view.

Code editing view:

Visual edit view:

2. Detailed introduction to the configuration file

The configuration file consists of app, deviceConfig, and Module, all of which must exist. Here is a basic config.json configuration file based on the basic HelloWorld application from HarmonyOS. If you need more details, please go to HarmonyOS ‘website.

Developer.harmonyos.com/cn/docs/doc…

2.1 the app

The app object contains the global configuration information for the application, as shown in the config.json configuration file for HarmonyOS’s base HelloWorld application:

"App" : {" bundleName ":" com. Example. The demo ", "vendor" : "example", "version" : {" code ": 1000000," name ":" 1.0.0 "}}Copy the code
The attribute name Child attribute name meaning The data type Can I default?
bundleName Indicates the package name of the application, which identifies the uniqueness of the application. string no
vendor Represents a description of the application developer. The value contains a maximum of 255 bytes. string The default value is null.
version Indicates the version of an application. object no
code Indicates the version number of the application. It is only used by HarmonyOS to manage the application and is not presented to end users of the application. The numerical no
name Indicates the version number of an application, which is displayed to end users. The value contains less than 127 bytes. string no

2.2 deviceConfig

DeviceConfig contains application configuration information on specific devices, including default, Phone, Tablet, TV, CAR, Wearable, liteWearable, and smartVision. The Settings on the default label are applicable to all devices. If you have special requirements on other devices, you need to configure the Settings on the label of this device type. The deviceConfig section of the config.json configuration file for HarmonyOS’s base HelloWorld program looks like this:

"deviceConfig": {}
Copy the code

2.3 the module

The Module object contains the HAP package configuration information, the basic properties that each Ability must define (such as package name, class name, type, and capabilities provided by Ability), as well as the permissions required by the application to access the system or other protected parts of the application. The module section of the config.json configuration file for HarmonyOS’s base HelloWorld program looks like this:

"module": {
    "package": "com.example.demo",
    "name": ".MyApplication",
    "mainAbility": "com.example.demo.MainAbility",
    "deviceType": [
      "phone"
    ],
    "distro": {
      "deliveryWithInstall": true,
      "moduleName": "entry",
      "moduleType": "entry",
      "installationFree": true
    },
    "abilities": [
      {
        "skills": [
          {
            "entities": [
              "entity.system.home"
            ],
            "actions": [
              "action.system.home"
            ]
          }
        ],
        "orientation": "unspecified",
        "name": "com.example.demo.MainAbility",
        "icon": "$media:icon",
        "description": "$string:mainability_description",
        "label": "$string:entry_MainAbility",
        "type": "page",
        "launchType": "standard"
      }
    ]
  }
Copy the code
The attribute name Child attribute name meaning The data type Can I default?
package The package structure name representing HAP should be guaranteed to be unique within the application. Use the reverse domain name format (consistent with HAP’s project directory is recommended). The value contains a maximum of 127 bytes. string no
name The class name for HAP. The reverse domain name is used. The prefix must be the same as the package name specified in the package tag of the same level, or the prefix can be “. Naming at the beginning. The value contains a maximum of 255 bytes. string no
mainAbility Indicates the name of HAP package’s entrance ability. string Ability of page type is not
deviceType Represents the type of device that allows Ability to operate. The pre-defined device types include Phone, tablet, TV, CAR, wearable, and liteWearable. String array no
distro Represents a specific description issued by HAP object no
deliveryWithInstall Indicates whether current HAP supports installation with the application. – true: Supports installation with applications. False: Installation with application is not supported. Boolean type no
moduleName The name of the HAP string no
moduleType Indicates the current HAP type, including entry and feature string no
installationFree Indicates whether the FA currently supports installation-free features. – true: the installation-free feature is supported and complies with the restriction of installation-free. False: the installation-free feature is not supported. Boolean type Entry. Hap can be default, feature. Hap cannot be default.
abilities Represents all abilities within the current module. The object array format is adopted, where each element represents a Ability object. An array of objects is
skills Indicates the characteristics of an Intent that Ability can receive. An array of objects is
orientation The display mode that represents this Ability. This tag only applies to Ability of page type. The values are as follows: – Unspecified: The system automatically determines the display direction. Landscape: Landscape mode. – Portrait: portrait mode. FollowRecent: Follows the most recent application in the stack. string is
name B. Ability C. Ability D. Ability Values can be represented using the reverse domain, by the package name and class name, such as “com. Example. Myapplication. MainAbility”; You can also use “. A class name at the beginning, such as “.mainability “. The label is only applicable to mobile phones, tablets, smart screens, cars and smart wearables. string no
icon Represents the index of the Ability icon resource file. Example value: $media:ability_icon. If, within the “skills” attribute of Ability, actions contains “action.system. Home” and entities contains “entity.system. Home”, Then the icon of Ability will also be the icon of application. If there are more than one Ability that meets the conditions, the icon of the Ability at the top is taken as the icon of the application. string is
description Ability. The value can be a descriptive content or a resource index of the descriptive content to support multiple languages. string is
label Represents the name that Ability displays to the user. The value can be the Ability name or a resource index to that name to support multiple languages. string is
type Indicates the type of Ability. The value can be: – page: indicates the FA developed based on the Page template to provide user interaction capabilities. Service: PA developed based on the Service template to provide the capability to run tasks in the background. – data: PA developed based on the data template to provide unified data access abstraction to the external. CA: indicates the Ability to be windowed by other applications. string no
launchType – Standard: indicates that there can be multiple instances of Ability. The Standard mode applies to most application scenarios. SingleMission: indicates that this Ability can only have one instance per task stack. – singleton: Indicates that Ability can have only one instance in all stacks. For example, a globally unique call interface uses the “Singleton” mode. The label is only applicable to mobile phones, tablets, smart screens, cars and smart wearables. string no

abilities -> skills

The attribute name Child attribute name meaning The data type Can I default?
skills Indicates the characteristics of an Intent that Ability can receive An array of objects is
entities Represents the category of capabilities of intents that can be received (such as video, desktop applications, etc.), and can contain one or more entities. String array is
actions Represents the action value of the Intent that can be received, and can contain one or more actions. String array is