Harmony application development knowledge base

Harmony application development knowledge base

  • Preface
  • text
    • 1. DevEco Studio version
    • 2. Mobile version
      • ① Environment variables
    • 3. API version
    • 4. Development language
    • 5. Operation and debugging

Foreword

Let me explain one thing first. If you are familiar with Android application development, you can also do Harmony application development with ease, but before that, you need to know some relevant knowledge about Harmony application development.

Text

Then the question is, why do I know these relevant knowledge points? Because I have been through the pitfalls once, and I will shed tears if I talk too much. I can only record them in writing. Of course, different application development will step on different pitfalls. This is understandable. The more you develop, the more you know, and the more you don’t know. , so this article will be continuously updated. Without further ado, let’s get to the point.

1. DevEco Studio version

First of all, you must understand the development tool DevEco Studio for Harmony application development.

First of all, you can download DevEco Studio, download address, install DevEco Studio, see this video: Demonstration video, you may need a Huawei account to watch this video, if you don’t have one, you first Register one. The version of DevEco Studio is also continuously updated. It is based on IDEA for secondary development, if Android Studio is the same. The latest version is DevEco Studio 3.1.

2. Mobile version

When developing Harmony applications on a real phone, what we need to know is the version of the Harmony phone. The version here is not the Harmony version at 0:00, but refers to the development API version. This is very important. As for why , I will elaborate on it later, so how do we check the API version of Hongmeng mobile phone? Just configure the tool through environment variables.

① Environment variables

First enter the system’s environment variables page and add a variable under system variables, as shown in the following figure:

Variable name: HUAWEI_SDK
Variable value: C:\Huawei\Sdk\hmscore\3.1.0\toolchains

What needs to be noted is the path of the editor you installed. The picture above is my path. You have to use your own path. 3.1.0 represents the sdk version, and the latest one is 3.1.0. After configuring, click OK, then find the Path variable under system variables and click Edit.


Then click New, enter %HUAWEI_SDK%, click OK, and confirm all the way. Next we Win + R open the run window, enter cmd to open the command line window.

Enter hdc

Appears as shown in the figure, indicating that the environment variable configuration is successful, but now your computer is not connected to the Hongmeng device, so No any target is displayed. Next, we open the developer mode of the Hongmeng phone, and then Connect the computer through the data cable. If a debugging pop-up window appears on the phone, check it, and then enter hdc -v.

Check the mobile API version, first enter hdc shell mode, like adb shell

hdc shell

Check the API version of your mobile phone

getprop hw_sc.build.os.apiversion

Check the version type of the mobile phone, it is usually Release.

getprop hw_sc.build.os.releasetype

Through query, I can know that my HUAWEI P30 is the Release version of API 6.

If the above command cannot be found, you can use

getprop persist.sys.ohc.apiversion

and

getprop persist.sys.ohc.releasetype

This is the instruction used in the case of high version API, if you find it troublesome, then so be it.

if [ -z $(getprop persist.sys.ohc.apiversion) ];then
echo $(getprop hw_sc.build.os.apiversion)
echo $(getprop hw_sc.build.os.releasetype)
else
echo $(getprop persist.sys.ohc.apiversion)
echo $(getprop persist.sys.ohc.releasetype)
fi

After hdc shell, if you copy this code and press Enter, you will see 6 and Release.

3. API version

What is the purpose of our efforts to obtain the API version of Hongmeng mobile phone above?

Compile SDK version API version Development language
3.1.0 9 ArkTS
3.0.0 8 ArkTS, JS
3.0.0 7 JS, Java
2.2.0 6 JS, Java
2.1.0 5 JS, Java
2.0.0 4 JS, Java

Through the above table, we can understand the compiled SDK version, supported API version and development language of DevEco Studio. As for the earlier API version, it doesn’t really matter whether you know it, because now the minimum is basically Harmony2.0. , generally 3.0. For example, the test machine I am currently using, HUAWEI P30, was upgraded from 2.0 to 3.0 before. I don’t know if there is still a chance to upgrade to 4.0.

At present, HarmonyOS is in a stage of rapid development. Each version has a lot of updates, and some functions will be gradually opened. If you have the conditions, getting a mobile phone with a high version of API will make your development more effective, because you The Harmony official website I see now mainly promotes ArkTS, and the compatibility will become better and better. In the future, ArkTS may be the only supported language, and the latest information on the forum is also ArkTS. As for Java, it is 21 years old. , and many of them are not maintained. First of all, you need to know the API version of your mobile phone. Otherwise, you will look at ArkTS for a long time and then find that it cannot be used during debugging. You still have to use Java or JS. This is what I call a pitfall.

4. Development language

The first thing to consider when developing a language is your compatibility. There is a pitfall here, and that is the issue of API version compatibility. For example, if you buy a Mate 60 Pro, it is far ahead, even though it is HarmonyOS4.0, then the API version you check through hdc may be 8 instead of 9. And my test machine P30 is 6, so if I create an API 9 project for development, I cannot conduct real-machine debugging on the P30 because the version is incompatible, so I cannot use the ArkTS language for development. You need to create a project that conforms to the mobile API version for development, such as API 6, as shown in the figure below.

Hongmeng phones with higher API versions can be compiled on projects with lower API versions. I am now creating an API 6 project and then debugging my colleague’s Mate 40 Pro on a real device. It is possible.

5. Operation and debugging

After we create a project, the first thing we need to do to run it is to configure Debug related information. This is somewhat similar to iOS. You can click DevEco Studio, File → Project Structure. If you are working on a new project, you may be required to log in to your Huawei account, and then you can enter Signing Configs to configure the local Debug certificate.

When the following information appears on this page, you can run debugging in local Debug.

You can check the Automatically generate signature item so that the editor can automatically change these configurations according to your changes in subsequent development.

At the same time, during the compilation and installation process, DevEco Studio will uninstall the previously installed applications and then install them again by default. The previous application data will not be retained, if you do not want this. You can enter Run → Edit Configurations....

Check Keep Application Data so that the application will be overwritten and installed.