DEV Community

Cover image for HarmonyOS development to understand the project structure
redvip8866
redvip8866

Posted on

HarmonyOS development to understand the project structure

This development tool is based on DevEco Studio 5.1.0 Release
API>=12
this article label: Hongmeng Development Tools/DevEco Studio

with the update and iteration of Api, the pattern has also changed when creating the project. The previous choice of Model, that is, the application Model, has long been removed, and the node environment does not need to be configured again. The number of device types has also increased from the original two to the current six. It can be said that the current Hongmeng development has gradually become concise and practical.

Image description

After we have created a project, the basic directory structure is shown in the following figure:

Image description

for a beginner, the first thing is to understand the directory structure of the project, know the meaning of each directory and each file, so as to facilitate future development work. In this article, we will summarize the directory by directory.

Introduction to non-primary documents

from top to bottom, let's give a brief overview of non-major documents, first of all .hvigor directory, which is used to store build profile information; .idea : It is used to store configuration information for the project; hvigor Directory : it is build configuration file information and a brand-new TS-based front-end build task orchestration tool. It combines npm package management mechanism and mainly provides task management mechanism, task registration orchestration, engineering model management, configuration management and other key capabilities, which is more in line with the development habits of ArkTS/JS developers; oh_modules: It is mainly used to store the dependency information of the third-party library. The third-party dependencies installed globally are also stored here, gitignore : There is nothing to say about this, it is mainly used for git filtering configuration; code-linter.json5 files, primarily configure the scope of code inspection and the corresponding effective inspection rules; hvigorfile.ts : application-level compilation build task scripts; local.properties : Files that are primarily used to store local attributes; oh-package.json5 : dependency configuration, you can set the three-party package dependency.

Introduction of main documents

in the actual development, and we are closely related to, and high contact with the following file directory, AppScope : Global common resource storage directory; entry : HarmonyOS engineering module, which will eventually compile and build a HAP package; build-profile.json5 application-level configuration information, including signatures, product configurations, etc.

In addition to the above three file directories, if we are modular or componentized projects, we will also increase the file directories of each module, which is also very important.entry they are all modules used to write code, but the types are different.

AppScope

AppScope is a global resource storage place. When there are multiple modules in our project, if there are common resources between modules, such as pictures, strings, colors, etc., they can be placed here to realize code reuse.

resources: used to store resource files used by applications/services, such as graphics, multimedia, strings, and layout files. 

base>element: a json file that contains resources such as strings, integer numbers, colors, and styles. Each resource is defined in json format 

boolean.json: boolean 

color.json: color 

float.json: Floating-point type 

intarray.json: Integer array 

integer.json: integer 

pattern.json: Styles 

plural.json: plural form 

strarray.json: String array 

string.json: string value 

base>media: multimedia files, such as graphics, video, audio and other files, supported file formats include:.png,. gif,. mp3,. mp4 and so on. 

rawfile: Used to store raw resource files in arbitrary format. rawfile does not match different resources based on the status of the device. You need to specify the file path and file name for reference. 

app.json5: global configuration information of the application.
Enter fullscreen mode Exit fullscreen mode

In addition to the sharing of resources, app.json5 also configures the basic information of the application, such as package name, application name, application version number, application icon, etc., which is also very important in development.

{
  "app": {
    "bundleName": "com.demo.myapplication",
    "vendor": "example",
    "versionCode": 1000000,
    "versionName": "1.0.0",
    "icon": "$media:app_layered_image",
    "label": "$string:app_name"
  }
}
Enter fullscreen mode Exit fullscreen mode

entry

entry is our main module and the area where our code is mainly written. Its directory structure is shown in the following figure:

Image description

not just entry, dynamic shared package and static shared package, is also our code editing area, it is different from the main module, is different in type, and the final compiled package is also different.

Each Directory, mainly introduced as follows:

src > main > ets: used to store the ArkTS source code. 
src > main > ets > entryability: the entry of the application/meta-service. 
src > main > ets > entrybackupability: Backup and Restore application access data. 
src > main > ets > pages: the pages contained by the app/meta-service. 
src > main > resources: used to store resource files used by applications/meta-service modules, such as graphics, multimedia, strings, layout files, etc. 
src > main > module.json5:Stage model module configuration file, which mainly contains HAP configuration information, application configuration information on specific devices, and application global configuration information 
build-profile.json5: current module information and compilation information configuration items, including buildOption and targets configuration. 
hvigorfile.ts: Module-level compilation build task script. 
oh-package.json5: Describes the package name, version, entry File (type declaration file), and dependencies of the three-party package.
Enter fullscreen mode Exit fullscreen mode

in addition to the root project has a oh-package.json5, each module also has its own oh-package.json5 file, if your dependency is only for the current module, then in the current module under the oh-package.json5 to configure, if multiple modules are used, can be configured in the root project under the oh-package.json5.

build-profile.json5

build-profile.json5 documents are mainlyApplication-level configuration information, including signatures, product configurations, etc., is important because you need to perform formal signature configuration in this file when the final signature is packaged. Similarly, if you want to run a real machine, you also need to perform signature configuration in this file.

Simple summary

this article is mainly aimed at the project catalog, a simple overview, for beginners friends, a simple understanding can be, with more and more contacts, it will naturally become familiar.

Top comments (0)