HarmonyOS Development: Understanding Application-Level Configuration Information

Foreword
this paper is based on api13.
After creating any project, we will find that an AppScope directory is created by default, which is where our application-level configuration information is located, it is automatically generated after the project is created and cannot be deleted. Its function is also obvious. One is to store global resources, and the other is to configure application-related information.
Directory structure
the default directory structure is shown in the following figure. app.json5 is used to configure application related information, such as package name, application icon, etc. resources is the resource directory and subdirectory base is the default directory of resources. The element directory is used to store basic elements such as strings, colors, and Boolean values. media is used to store files in non-text formats such as pictures, audio, and video.
app.json5 file
the configuration information of the application. The default configuration is as follows:
{
"app": {
"bundleName": "com.abner.demo",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}
field-related overview:
property | overview |
bundleName | the name of the application Bundle, which is used to identify the uniqueness of the application. |
vendor | the description of the application developer. The value is a character string with a length of no more than 255 bytes. |
versionCode | the version number of the application. The value is a positive integer less than 2 ^ 31. |
versionName | Identifies the version number of the application that is presented to the user. |
icon | the icon that identifies the application. The value is the index of the icon resource file. |
label | the name of the application. The value is the index of the string resource. The length of the string cannot exceed 63 bytes. |
resources Directory
resource Directory, if your project has multiple modules, some common resources can be put here, such as picture resources, colors, strings, etc.
base is the default directory. In addition to base, you can create other directories, such as internationalization language settings, color mode settings, etc.
There are many resource files that can be created in the element directory, such as colors, strings, etc. The specific files can be created as follows:
Representing element resources, each type of data is represented using a corresponding JSON file (only file types are supported in the directory).
- boolean, Boolean type
- color, colour
- float, Floating point type, with a range of -2 ^ 128-2 ^ 128
- intarray, integer array
- integer, Integer, with a range of -2 ^ 31-2 ^ 31-1
- plural, Plural form
- strarray, string array
- string, character string
simple example
because it is global, resources can be directly obtained under any Module, for example, I defined a string.
In the code, it can be directly obtained in the same way as this Module is used.
Other resource calls are basically the same as the above usage.
Summary
in actual development, if there are common resources, it is recommended that everyone put them in the AppScope Directory. For some application-level information, such as the name of the application and the icon of the application, although it can be configured under Moulde, it is more recommend to use app in the AppScope directory for more convenient management. json5 is the main, of course, it is only recommend. In fact, both can be realized. You can choose one of them.
Subscribe to my newsletter
Read articles from AbnerMing directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
