Hongmeng App Development (4) --- First encounter with Hongmeng Development

table of Contents

Hongmeng App Development

The blogger made everyone realize the charm of Hongmeng's development through the three components introduced above. However, then again, for beginners, it may not be easy to get started directly without analyzing the project directory.

Today, the blogger will analyze the directory structure of Hongmeng clearly for everyone to facilitate subsequent knowledge learning.

Build a Hongmeng development environment

First of all, we need to install Java JDK. Most of the blogger's subsequent explanations are to develop Hongmeng App in Java language, so there must be a Java JDK in the system. The installation address:


Then, install the DevEco Studio, the development tool of Hongmeng. The specific URL is:


Here you can select the system version to install:


Create a Hongmeng project

Hongmeng's development tools are relatively very brief, and you can see at a glance how to create a new project and open an existing project. As shown in the figure below:

Create project

Here, we select the empty Hongmeng App interface to create, and then enter the name of the App and the package name.

Package names

At this point, the Hongmeng App project we created has been successful.

The directory structure of the Hongmeng project

After the project is created, let's take a look at its overall directory structure, as shown in the following figure:

Directory Structure

gradle: Gradle configuration file, which is automatically generated by the system and generally does not need to be modified.

entry: This is the folder we need to use in most of our development. Its directory structure is as follows:

entry directory structure

libs: The imported Java reference package is placed here. For example, if you need to use java to send mail in the project, you can put the mail.jar package here and then import the project.

src-main-Java: The Java code of the development project is placed here, and we mainly develop it here.

  • MainAbilitySlice: It can be imagined as drawing paper. A drawing board can be placed on multiple drawing papers. For example, in Huawei's parallel vision, there is one page on the left and one page on the right. It is equivalent to placing two MainAbility Slices in MainAbility. Equivalent to Fragment in Android development.
  • MainAbility: Think of it as a drawing board, which is equivalent to Activity in Android development.
  • MyApplication: It is equivalent to MyApplication in the Android project, but Android inherits Application, and Hongmeng inherits AbilityPackage. The functions are basically the same. The initial configuration of the project is carried out here.

src-main-resources: used to store resource files.

  • media: Store the local multimedia content that needs to be used in the project. Multimedia includes pictures, videos, audios, etc. It is equivalent to the drawable in the Android project.
  • element: stores character strings, vector size data, style file content, etc., which is equivalent to values ​​in the Android project.
  • layout: Stores the XML layout file, which is equivalent to the layout in the Android project.
  • graphic: Store the content of the shape tag, which is often used to set the background-element background attribute. It is placed in the drawable in Android. Here, the folder is listed separately for placement.

src-main-config.json: HAP manifest file, equivalent to AndroidManifest.xml in the Android project, used to configure MainAbilitySlice content, etc.

build.gradle: The compilation configuration file of the entry module.

src-test: The directory for writing test files.

It should be noted that, at least most of the explanations in the component chapter, only involve editing the content in the entry file. As for other documents, we will talk about them later, so we will introduce them when we explain them later. (For example, what files are used for packaging HAP applications, etc.)

Run Hongmeng App

Considering that Hongmeng devices have not yet been fully popularized, here is how to use the simulator to run the Hongmeng App. In the future, when I explain how to export the Hongmeng Hap application, we will introduce signatures and other content.

First of all, if we need to run the Hongmeng App, we need to click Tool-HVD Manager to create an emulator, as shown in the following figure:

turn on

log in

After clicking, a web login request will pop up. If there is a Huawei mobile phone, directly use the Huawei mobile phone to scan the code to log in. If it is another device, register or log in with an account.

Here, after logging in, an interface as shown in the figure below will pop up, just click Allow.

Insert picture description here

After returning to DevEco Studio, the following interface will appear, here also click to agree to Agree:

Insert picture description here

Device Selection

As shown in the figure above, after clicking Agree, the device selection will appear. Because we are testing a mobile app, just run P40 directly.


After running, the simulator will appear on the right side of the compiler. If you need to run the project, you can directly click Run-run entry to test the App on the simulator.