The first step of HarmonyOS development, familiar with the development tool DevEco Studio

As the saying goes, if a worker wants to do a good job, he must first sharpen his tools. The first step into HarmonyOS is to develop tools first. Of course, there are many explanations on the official website and other blogs about the use of development tools, but they are not There is no overview according to the commonly used functions. If you need a certain function, you have to search and search, which is very inconvenient. Based on this, this article mainly uses common function points as an overview, hoping to help developers who learn HarmonyOS.

The main functions of this article are summarized as follows:

1. Tool download and environment configuration

2. Set the theme style

3. Set the code font size

4. Api reference and rapid development guide in the IDE

5. Set header annotations and method annotations

6. Set the code template and generate shortcut keys

7. Breakpoint debugging

8. Print and view logs

9. Global and local search

10. Creation and use of simulator

11. Download different versions of SDK

1. Tool download and environment configuration

Regarding the download and installation of the tool, I will not outline it here. You can follow the official website step by step. The official website step address:

https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/software_install-0000001053582415-V3?catalogVersion=V3

Of course, if you want to use the ArkUI-X framework, the version requirement is V4.0 Beta2, you can download it from the link below:

https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/OpenHarmony-v4.0-beta2.md#%E9%85%8D%E5%A5%97%E5%85%B3%E7%B3%BB

After downloading and installing, you need to enter the configuration environment, you can follow the official website documentation step by step:

https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/environment_config-0000001052902427-V3?catalogVersion=V3

2. Set the theme style

The default code theme style is dark, as shown in the following figure:

If you don't like it, you can change it by following the steps below:

1. Click Flie->Settings->Appearance&Behavior->Appearance in the upper left corner, click Theme, and select your favorite theme style in the pop-up drop-down box, as shown below:

Choose your favorite theme style:

2. In addition to the above steps to enter the setting page, you can also use the shortcut key, Ctrl+alt+S. In addition, after opening the project, click the setting icon on the right, and you can also choose to enter the setting page.

3. Set the code font size

In the newly installed IDE, the code font is very small, which looks very tired to the eyes. You can open the settings page, find the Font button in the Editor option, click it, and change the font size to your own comfort.

4. Api reference and rapid development guide in IDE

Api reference

In order to better serve developers, DevEco Studio has prepared common Api guides for everyone in the tool. There are not only cases, but also code effects. In the IDE market, I have to say that it is really considerate .

Click the Help button in the top navigation bar and select API Reference:

Regarding the basic use of API and components, the list is complete, not only the use case, the effect of the case, but also the corresponding code, which is absolutely official and authoritative.

Quick Development Guide

Click the Help button in the top navigation bar and select the first Quick Start. From this window, you can easily find what you need according to the relevant indexes.

conclusion of issue

Click the Help button in the top navigation bar and select FAQ. In this window, you can retrieve some common troubleshooting issues.

5. Set header annotations and method annotations

The header comment and method comment of the file are essential in development, and they are not included in the IDE by default. If you manually add comments every time you create a file, it is not too painful. Fortunately, each IDE provides We leave room for dynamic configuration.

set header annotation

According to the above steps, open the settings page in turn, select Editor, then select File and Code Templates, find ArkTS File, and write your own header comments on the right. How to specify it depends on your company's specifications.

After the setting is complete, click ok, and the ets file created later will carry the header comment:

method annotation

Open the settings page in turn, select Editor, click Live Templates, and click Add on the right, as shown in the following figure:

On a certain method, you can automatically generate comments by tapping the custom shortcut key twice, which is very convenient:

Record a gif, we might as well look at it intuitively:

6. Set the code template and generate shortcut keys

The setting of the code template is the same as the previous custom method annotation, which is mainly used for code reuse and quick generation of corresponding code logic, such as a piece of network request logic, such as a list implementation, etc.

Open the settings page and add a code template, which is consistent with adding a method comment template:

View the effect:

Seven, breakpoint debugging

Breakpoint debugging is very important in actual development, and it is absolutely even more powerful for us to troubleshoot problems.

1. How to open the breakpoint mode?

On the left side of the code you want to debug, single-click to lock the start position of the breakpoint. Of course, multiple breakpoints can be hit.

If the project is not started, click the breakpoint debugging button, which is the green crawler button, to enter the debug mode.

If the project is already running, you can click the button next to it and select the program to debug.

When you hit the breakpoint button and a checkmark appears, it proves that you have entered the debug mode.

2. How to make a breakpoint

After entering the breakpoint mode, it can be triggered on the application. What I tested here is that after clicking the text, it enters the breakpoint, and the corresponding debugging can be carried out through the following buttons.

8. Print and view logs

Log and breakpoint debugging are important tools for checking code results and troubleshooting errors during development. The development of HarmonyOS officially launched two languages: ArkTS language and JS language. Compared with performance, ArkTS is the first development language for mobile terminals. , since ArkTS is further extended on the ecological basis of TypeScript (TS for short), inherits all the features of TS, and is a superset of TS, so the printing method of TS can also be used to print logs.

1. Console printing is the same as Js printing.

Do it where you need to print, just output the log.

 console.log("打印了一条日志");

The printed results are as follows:

Of course, you can also print according to the log level:

                console.info("普通的信息");
                console.debug("DEBUG级别的信息");
                console.warn("警告的信息");
                console.error("错误的信息");

Show results:

2. HiLog log printing

HiLog log system: Allows applications/services to print log content according to specified types, specified levels, and specified format strings, helping developers understand the running status of applications/services and better debug programs.

Print example:

hilog.info(0xFF00, "testTag", "%{public}s World", "hello")

This line of code means to output a common message, the format string is: "%{public}s World". The variable parameter "%{public}s" is a public string.

The main methods provided by hilog are as follows:

method

overview

debug(domain: number, tag: string, format: string, ...args: Array<Object>)

Output DEBUG level logs. DEBUG level logs are only used for application/service debugging.

You can use the command "hdc shell hilogcat" to set the printable log level to DEBUG in the terminal window or cmd of DevEco Studio.

info(domain: number, tag: string, format: string, ...args: Array<Object>)

Output INFO level logs. INFO level logs represent general information.

warn(domain: number, tag: string, format: string, ...args: Array<Object>)

Output logs at WARN level. WARN level logs indicate that there are warnings.

error(domain: number, tag: string, format: string, ...args: Array<Object>)

Output logs at ERROR level. ERROR level logs indicate that there was an error.

fatal(domain: number, tag: string, format: string, ...args: Array<Object>)

Output logs at FATAL level. The FATAL level log indicates a fatal error or an unrecoverable error.

The parameters domain and tag should be the same as those used in isLoggable.

Parameter format: format string for formatted output of logs. Multiple parameters can be set in the format string. For example, the format string is "%s World", and "%s" is the variable parameter identifier whose parameter type is string. The specific value is defined in args.

Each parameter needs to add a privacy flag, which is divided into {public} or {private}, and the default is {private}. {public} indicates that the log printing result is visible; {private} indicates that the log printing result is not visible, and the output result is <private>.

When debugging, you can use the command "hilog -p off" to turn off the privacy switch and display the private log content in plain text.

Parameter args: can be 0 or more parameters, which is the parameter list corresponding to the parameter type in the format string. The number and types of parameters must correspond to the identifiers in the format string.

3. View log information

Click the log button at the bottom to view the current log information.

You can also change the color of the log output if you like:

Click Settings, click color.

Just set the color you like.

Select the output log level:

Filter by content:

Set filter template:

You can click Config custom filter to add through the filter window

Or by clicking the Settings button, click the Filter option to add filtering.

Just fill in the information you want to filter.

Nine, global and local search

1. Partial search of files

Use the shortcut key Ctrl+F to search within the file.

2. Global search

Double-click the Shift key, or click the search button on the right:

Then in the pop-up dialog box, you can search:

3. Whole project search

Searches can be performed as follows:

You can search for the entire project, or after changing the shortcut key to Eclipse, the shortcut key Ctrl+H will pop up.

Ten, the creation and use of the simulator

1. Always preview

Preview from time to time, you can preview the function of the current page, just click the preview button on the right.

2. Simulator creation

Click the Tools option at the top, and click the Device Manager option:

Or click on the left option of Run and find Device Manager in the drop-down.

Select the corresponding device to create, follow the steps and execute the next step. After the creation is complete, you can click the green start button on the right to start each time:

Simulator effect:

3. Remote simulator

The IDE provides the use of the remote emulator. You can click the corresponding option and log in to the Huawei developer account.

Select a remote device:

remote start

11. Download different versions of SDK

Same as the previous steps, open the settings page, find the SDK option, and download the corresponding version.

The above functions are just the tip of the iceberg of DevEco Studio. Due to the limited space, many functions such as memory analysis, git usage, file viewing, etc. cannot be listed for the time being, and will be added later. I hope it can help you who are learning HarmonyOS development.

Guess you like

Origin blog.csdn.net/ming_147/article/details/132431752