Prepare the HarmonyOS development environment

introduction

Before starting HarmonyOS development, you need to prepare the development environment. This chapter will guide you in detail on how to install the HarmonyOS SDK, configure the development environment, and create a HarmonyOS project.

Table of contents

    1. Install HarmonyOS SDK
    1. Configure development environment
    1. Create HarmonyOS project
    1. Summarize

1. Install HarmonyOS SDK

HarmonyOS SDK is a software development kit for developing HarmonyOS applications. It includes tools such as compilers, simulators, and debuggers.

1.1 Download HarmonyOS SDK

  • Open the Huawei HarmonyOS official website .
  • Jump to the developer community.
  • In the developer community, find the download page for the HarmonyOS SDK .
  • Choose the version appropriate for your operating system.
  • Click the "Download" button to download the HarmonyOS SDK.

1.2 Install HarmonyOS SDK

  • Open the downloaded HarmonyOS SDK installation package.
  • Double-click the installation file to start the installation program.
  • Follow the installer's instructions, select the installation path, and accept the license agreement.
  • Click the "Install" button to start installing HarmonyOS SDK.
  • After the installation is complete, click the "Finish" button.

2. Configure the development environment

Configuring the development environment is an important step, which will affect your development efficiency.

2.1 Configure JDK

  • Make sure you have JDK installed on your computer. If it is not installed, please install JDK first.
  • Configure the JAVA_HOME environment variable.
    • Open the Control Panel.
    • Click "System".
    • Click "Advanced system settings".
    • Click "Environment Variables".
    • In "System Variables", click "New".
    • Enter "Variable Name" as JAVA_HOME.
    • Enter the "Variable Value" as the installation path of the JDK.
    • Click the "OK" button.

2.2 Configure development environment

  • Run the installed DevEco Studio. For first time use, please select Do not import settings and click OK.
  • Enter the DevEco Studio operation wizard page and modify the npm registry. DevEco Studio has preset the corresponding warehouse (the default npm warehouse may be inaccessible or slow for some developers). Directly click Start using DevEco Studio to proceed to the next step. .
  • To set Node.js information, you can specify the locally installed Node.js (the Node.js version is required to be v14.19.1 and above, and lower than v15.0.0; the corresponding npm version is required to be 6.14.16 and above, and lower than 7.0.0 version); if there is no suitable version locally, you can select the Download button to download Node.js online. This example takes downloading Node.js as an example. After selecting the download source and storage path, click Next to proceed to the next step. Wait for Node.js installation to complete, then click Finish to proceed to the next step.
  • On the SDK Components Setup interface, set the OpenHarmony SDK and HarmonyOS SDK storage paths, and click Next to proceed to the next step.
  • On the pop-up SDK download information page, click Next, and in the pop-up License Agreement window, read the License Agreement and agree to the License Agreement (you must accept the License Agreement of both OpenHarmony SDK and HarmonyOS SDK), and click Next to start downloading the SDK.
  • After waiting for the SDK download to complete, click Finish to complete the SDK download, and the interface will enter the DevEco Studio welcome page.
  • Configure HDC tool environment variables (Windows adds environment variables, adds HDC port variable name: HDC_SERVER_PORT, variable value can be set to any unoccupied port, such as 7035)

2.3 Configure the simulator

  • Open the HarmonyOS SDK.
  • In the SDK, find the simulator's configuration page.
  • Follow the instructions on the configuration page to configure the emulator.

2.4 Configure IDE

  • Open the HarmonyOS SDK.
  • In the SDK, find the IDE's configuration page.
  • Follow the instructions on the configuration page to configure the IDE.

3. Create HarmonyOS project

Creating a HarmonyOS project is the first step to starting development.

3.1 Select project template

  • Open the HarmonyOS SDK.
  • In the SDK, find the Create Project page.
  • On the Create Project page, select a project template.

3.2 Configuration items

  • Enter a name for the project.
  • Enter the package name of the project.
  • Select the target platform for your project.

3.3 Create project

  • Click the "Create" button.
  • HarmonyOS SDK automatically creates the project.

3.4 Project directory structure

  • entry: HarmonyOS engineering module, compile and build to generate a HAP package.
    • src > main > ets: used to store ArkTS source code.
    • src > main > ets > MainAbility: the entry point of the application/service.
    • src > main > ets > pages: Pages included in the application/service.
    • src > main > resources: used to store resource files used by applications/services, such as graphics, multimedia, strings, layout files, etc. For detailed description of resource files, please refer to the classification of resource files.
    • src > main > config.json: module configuration file. It mainly includes the configuration information of the HAP package, the configuration information of the application/service on the specific device, and the global configuration information of the application/service. For specific configuration file description, see Configuration File Description (JS/ArkTS).
    • build-profile.json5: Current module information, compilation information configuration items, including buildOption, targets configuration, etc.
    • hvigorfile.ts: Module-level compilation and build task script, developers can customize related tasks and code implementation.
  • build-profile.json5: Application-level configuration information, including signatures, product configurations, etc.
  • hvigorfile.ts: Application-level compilation and build task script.
  • Build the page: Click "entry > src > main > ets > pages" and open the "index.ets" file
@Entry
@Component
struct Index {
  @State message: string = 'Hello World'

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
        Button() {
          Text('Next').fontSize(30).fontWeight(FontWeight.Bold)
        }.type(ButtonType.Capsule).margin({top:20}).backgroundColor('#0D9FFB').width('40%').height('5%')
      }
      .width('100%')
    }
    .height('100%')
  }
}

4. Summary

This chapter provides detailed guidance on how to install the HarmonyOS SDK, configure the development environment, and create a HarmonyOS project. Now, you are ready to start HarmonyOS development.

Guess you like

Origin blog.csdn.net/xudepeng0813/article/details/132620017