目录

Creating a Project

Before starting to develop an app/atomic service, you must create a project. DevEco Studio will automatically create sample code and a resource template depending on the type of your project.

When you are ready to start a new project, DevEco Studio has a variety of templates that support different devices and API versions. It would be helpful to check out the specifics of each template to find the one that fits your needs best. For details, see Introduction to Project Templates.

When running a project, it is recommended that each running window have more than 2 GB available memory space.

Creating a HarmonyOS Project

  1. Open the project wizard using either of the following methods:

    • If no project is open, select Create Project on the welcome page.
    • If a project is already open, choose File > New > Create Project on the menu bar.

  2. Following the project creation wizard, select Application or Atomic Service. Select an ability template and click Next.

    • Atomic service projects are supported since API version 11.
    • Atomic service projects do not support development in C++.
    • Currently, [CloudDev]Empty Ability is available only in the Chinese mainland.

  3. On the project configuration page, set the basic project information.

    • Project name: name of the project. It can be customized and must start with a letter. The value is a string of 1 to 200 characters, including uppercase letters, lowercase letters, digits, and underscores (_).
    • Bundle name: bundle name of the app/atomic service, which uniquely identifies the app/atomic service.
    • Save location: path for storing project files. The path consists of uppercase letters, lowercase letters, digits, and underscores (_).
    • Compatible SDK: the earliest compatible API version.
    • Module name: name of the module.
    • Device type: device type supported by the project template. For details about device types, see deviceTypes.
    • C++ Standard: C++ standard library. Since DevEco Studio 6.0.1 Beta1, the following values are available: Toolchain Default, C++11, and C++14. You can select one for your project.

    A bundle name must meet the following requirements:

    • The bundle name contains at least three segments, separated by periods (.). Each segment can contain only letters, digits, and underscores (_). Example: com.example.myapplication.
    • The first segment starts with a letter, and other segments start with a digit or letter. Each segment ends with a digit or letter. Example: com.01example.myapplication.
    • Consecutive periods (.) are not allowed, for example, com.example..myapplication.
    • The bundle name contains 7 to 128 characters.

    Description of the Compatible SDK field

    • Since version 26.0.0, the View API version distribution feature is added to all project templates except the [Lite]Empty Ability project template. Click View API version distribution to view the distribution of each API version on HarmonyOS devices, where Percentage indicates the proportion of active devices using that API version, and Cumulative Percentage indicates the cumulative proportion of active devices for all API versions up to and including this version. The Compatible SDK field displays the highest API version at which the cumulative proportion of active devices exceeds 90% by default.
    • The View API version distribution feature is available only in the Chinese mainland.

  4. Click Finish. DevEco Studio will automatically generate the sample code and resources that match your project type. Wait until the project is created.

(Optional) Creating an OpenHarmony Project

To create an OpenHarmony project for application development, perform the following steps:

  1. After creating a HarmonyOS project, perform the following operations in the project-level build-profile.json5 file:

    For API version 26.0.0 or later:
    1. Add the compileSdkVersion field to the project-level build-profile.json5 file and assign a string as its value.
    2. Change the runtimeOS field from HarmonyOS to OpenHarmony.
    "app": {
      "signingConfigs": [],
      "products": [
        {
          "name": "default",
          "signingConfig": "default",
          "compileSdkVersion": "26.0.0",    // Set the version for building the OpenHarmony app, for example, 26.0.0 in this case.
          "targetSdkVersion": "26.0.0",     //Set the target SDK version for running the OpenHarmony app, for example, 26.0.0 in this case.
          "compatibleSdkVersion": "26.0.0", // Set the earliest SDK version compatible with the OpenHarmony app, for example, 26.0.0 in this case.
          "runtimeOS": "OpenHarmony",
          "buildOption": {
            "strictMode": {
              "caseSensitiveCheck": true,
              "useNormalizedOHMUrl": true
            }
          }
        }
      ],
    For API versions earlier than 26.0.0:
    1. Add the compileSdkVersion field to the project-level build-profile.json5 file.
    2. Set the compatibleSdkVersion, compileSdkVersion, and targetSdkVersion (if any) fields to numeric values.
    3. Change the runtimeOS field from HarmonyOS to OpenHarmony.
    "app": {
      "signingConfigs": [],
      "products": [
        {
          "name": "default",
          "signingConfig": "default",
          "compileSdkVersion": 24,    // Set the version for building the OpenHarmony app, for example, 24 in this case.
          "targetSdkVersion": 24,     // Set the target SDK version for running the OpenHarmony app, for example, 24 in this case.
          "compatibleSdkVersion": 24, // Set the earliest SDK version compatible with the OpenHarmony app, for example, 24 in this case.
          "runtimeOS": "OpenHarmony",
          "buildOption": {
            "strictMode": {
              "caseSensitiveCheck": true,
              "useNormalizedOHMUrl": true
            }
          }
        }
      ],

  2. Click Sync Now to start synchronization. In the Sync Check dialog box, click Yes to switch the phone type in the module.json5/config.json file to the default type and delete other device types that are not applicable to OpenHarmony. The project is created once the synchronization is successful with no errors.

If you are creating an OpenHarmony project using a native C++ template, to enable your app to run on RK development boards, add "abiFilters": "armeabi-v7a" to buildOption/externalNativeOptions in the build-profile.json5 file of the corresponding native module.