Building HarmonyOS development environment

Introduction to Yi Hongmeng:

1.1 HarmonyOS is a distributed operating system developed by Huawei. It is compatible with Android, but different from Android. It is not only targeted at mobile phone systems. It focuses more on the Internet of Things and smart terminals, and has been updated to version 4.0.

1.2 The HarmonyOS software programming language is ArkTS, which is based on an extension of TypeScript, and TypeScript is an extension of JavaScript, so it will be easier if you have JavaScript experience.

e758bcf1c81e4a05803554c1b2944c52.png

2. Building HarmonyOS programming environment

2.1 HarmonyOS software programming tool is DevEco Studio, official download link: https://developer.harmonyos.com/cn/develop/deveco-studio

25d6cf4c5e3b45afaca3d4364f986144.png

2.2 Click to install after downloading

544dc3ad0481455c8216a0cadabc0ed1.png

2.3 Install and run

5fa65d6024014e9c8aff423d928fff16.png

2.4 Click Agree to enter the configuration

df87eed0b4134d24b94c81e0074f4fb9.png

2.5 Enter the DevEco Studio configuration page. First, you need to perform basic configuration, including the installation path settings of Node.js and Ohpm. Select the appropriate path to download from the Huawei image.

5a07748f6026442e9418f252e10ecee0.png

2.6 Click 'Next' to enter the SDK configuration and set it to the appropriate path

e174fe9366d740059ba3f8c6da08117d.png

2.7 After clicking 'Next', the 'SDK License Agreement' will be displayed. After reading the relevant agreement, check 'Accept'.

c7b828d08b29472f9f8d0b2b956fc734.png

2.8 Click 'Next' to enter the configuration preview page, where you can confirm the configuration items.

14b12ba2cf4248f9be720e1537b30367.png

 2.9 After confirmation, click 'Next' to proceed to the next step.

da3aeae98b064047b461edd2531a1614.png

2.10 Wait for the automatic download of the configuration to complete. After completion, click 'Finish'. The IDE will enter the welcome page, and we have successfully configured the development environment.9808182e08bd4bfc933009088a1b9b74.png

3. Create a project

3.1 Click Create Project on the welcome page to enter the project creation page.

f6d0bd1a56904723a8054b67c1fcbab1.png

3.2 Select 'Application', then select 'Empty Ability', and click 'Next' to enter the project configuration page.

49943d1a9c1048f3b0ae67af06de6e39.png

 3.3 In the configuration page, the details are as follows:

  • Project name is a project name that developers can set by themselves. Here you can change it to your own project name according to your choice.
  • Bundle name is the package name. By default, the application ID will also use this name. The corresponding ID needs to be consistent when the application is published.
  • Save location is the project save path. It is recommended that users set the corresponding location by themselves.
  • Compile SDK is the compiled API version, and API9 is ​​selected by default here.
  • Select the Stage model for Model and keep the others as default.
  • Then click "Finish" to complete the project creation and wait for the project synchronization to be completed.

3.4 After entering the IDE, you can see that most editors are similar. The entire IDE interface can be roughly divided into four parts, namely the code editing area, notification bar, project directory area and preview area.

d944e593d5cb4ded8aef877bea262f43.png

3.5 Click Previewer in the upper right corner to preview the corresponding file UI display effect. 

e68211318d984bb2902c4ac1cb11f730.png

Four debugging

4.1 Click Tools>Device Manager on the top toolbar.

408fa10d4c0f4393a6e6d79c9bda0c5b.png

4.2 Select Local Emulator, set the appropriate Local Emulator Location storage address, and then click '+New Emulator'

5d94af2fdfc84150bfe8b7551da2d761.png

4.3 Select the Huawei_Phone mobile phone simulator and click 'Next' to enter the simulator system download page.

c23e19e6b968493dbcbfe08a17d9f7a1.png

4.4 Select to download the system image of api9, then click 'Next' and wait for the download to complete.

0652032cd82d4ed6814767224873b130.png

4.5 After the download is completed, the created mobile phone emulator will appear on the Local Emulator page. Click the Actions button to start the emulator.

9e4ad3991b4948e8a035d8720eb6f1d7.png

4.6 After the simulator starts, click the start button above to run the Hello World project on the simulator.

6d7d4645b13b4d5e992e26990c55b87d.png

4.7 After the IDE is built, you can see the running effect on the simulator, and we have completed running the Hello World project on the simulator.

b7f1923b4fde41ca89b7d012d7b14b28.png

Introduction to five projects

5.1 Project directory

a94ad8010fc4460c8086530a5e28a413.png

  • AppScope stores resource files needed globally by the application.
  • Entry is the main module of the application, which stores the code, resources, etc. of the HarmonyOS application.
  • oh_modules is the dependency package of the project, which stores the source files that the project depends on.
  • build-profile.json5 is project-level configuration information, including signatures, product configurations, etc.
  • hvigorfile.ts is an engineering-level compilation and build task script. hvigor is a new automated construction tool based on the task management mechanism. It mainly provides core capabilities such as task registration and orchestration, engineering model management, and configuration management.
  • oh-package.json5 is a project-level dependency configuration file, used to record the configuration information of imported packages.

5.2 Module directory

bef0b3eee99d4a048cf0c58af23ebe88.png

The entry>src directory mainly contains the overall main folder, unit test directory ohosTest, and module-level configuration files.

  • In the main folder, the ets folder is used to store the ets code, the resources file stores the multimedia and layout files in the module, and the module.json5 file is the configuration file of the module.
  • ohosTest is the unit test directory.
  • build-profile.json5 is module-level configuration information, including compilation and build configuration items.
  • The hvigorfile.ts file is a module-level build script.
  • oh-package.json5 is a module-level dependency configuration information file.

Enter the src>main>ets directory, which is divided into two folders: entryability and pages.

  • entryability stores ability files, which are used for current ability application logic and life cycle management.
  • pages stores UI interface related code files, and an Index page will be generated initially.

5.3 AppScope>app.json5 is the global configuration file of the application, which is used to store the common configuration information of the application.

4fc860c16a7440f5a188cc45013d4309.png

  • bundleName is the package name.
  • vendor is the application supplier.
  • versionCode is used to distinguish application versions.
  • versionName is the version number.
  • icon corresponds to the application's display icon.
  • label is the application name.

5.4 The src/main/resources/base/profile/main_pages.json file saves the path configuration information of the page. All pages that need to be routed must be configured here.

321f0715832445ebbadef107712bccb6.png

Six compilation problems

6.1 If the releaseType field configured in the project does not match the image version of the device (simulator and real machine), an INSTALL_PARSE_FAILED_USESDK_ERROR error will be reported during runtime, as shown in the figure below.

6.2 Solutions:

When running an app/service in a device, the compileSdkVersion and compatibleSdkVersion in the build.gradle (API4-7) or build-profile.json5 (API8 and above) files, as well as the SDK Stage (Beta or Release) need to match the device's apiVersion, The releaseTypes must match each other to function properly. The specific modification method is as follows

6.3. Open the CMD command line tool under the Sdk\hmscore\{version number}\toolchains file in the HarmonyOS SDK storage directory , and execute the following command to query the apiVersion and releaseType values ​​of the real device.

On mobile/tablet HarmonyOS 3.1 Release devices:

hdc -c shell 
getprop persist.sys.ohc.apiversion
getprop persist.sys.ohc.releasetype

On mobile/tablet devices before HarmonyOS 3.1 Release:

hdc -c shell
getprop hw_sc.build.os.apiversion
getprop hw_sc.build.os.releasetype

as follows 

 

Open the module's build.gradle (API4-7) or open the project's build-profile.json5 (API8-9) file and check compileSdkVersion and compatibleSdkVersion.

View compileSdkVersion and compatibleSdkVersion in the module's build.gradle (API4-7) file

Check compileSdkVersion and compatibleSdkVersion in the project's build-profile.json5 (API8-9) file

6.4, click File  >  Settings  > SDKs > HarmonyOS to view the SDK stage corresponding to compileSdkVersion. For example, the Stage corresponding to API Version 7 in the figure below is Release.

6.5. According to the queried device apiversion, releaseType, and SDK Stage values, query the matching relationship in the following table to modify the values ​​of compileSdkVersion and compatibleSdkVersion. Among them, compileSdkVersion needs to modify the value in build.gradle of the project and each module; compatibleSdkVersion needs to modify the value in build.gradle of each module.

apiVersion

releaseType

compileSdkVersion

SDK Stage

compatibleSdkVersion

4

Release

4

Release

4

4

Release

5

Release

4

5

Release

5

Release

4 or 5

5

Release

5

Release

4 or 5

5

Release

6

Release

4 or 5

5

Release

6

Release

4 or 5

6

Release

5

Release

4 or 5

6

Release

6

Release

4 or 5 or 6

6

Release

5

Release

4 or 5

6

Release

6

Release

4 or 5 or 6

7

Release

7

Release

4 or 5 or 6 or 7

7

Release

6

Release

4 or 5 or 6

8

Release

6

Release

4 or 5 or 6

8

Release

8

Release

8

9

Release

9

Release

9

6.6. After the current application version matches the device image version, if this error is still reported and the device image version has been updated to 3.1 Release version, it means that the currently used DevEco Studio version does not match the image version running on the device. Please upgrade DevEco Studio. To version 3.1 Release, run/debug on the new version of DevEco Studio.

Guess you like

Origin blog.csdn.net/qq_29848853/article/details/132956836