How do I create my first ArkTS app in DevEco Studio?

Published:

arktstutorialdeveco-studio

Short answer: In DevEco Studio, create a new project with the Application > Empty Ability template, open entry/src/main/ets/pages/Index.ets, and click Run after selecting a device or emulator. The template already contains a working Hello World page written in ArkTS and ArkUI.

What do you need first?

How do I create the project?

  1. Open DevEco Studio and create a new project.
  2. Select Application, then the Empty Ability template.
  3. Fill in the project fields: project name, Bundle name (the defaults are fine for a first app), Compatible SDK (for example 5.0.0(12)) and the model, Stage.
  4. Finish and wait for the project to sync.

Note: since DevEco Studio 4.1 Beta1, a new project is created for HarmonyOS by default. To target OpenHarmony, change the project-level build-profile.json5:

"compileSdkVersion": 12,
"compatibleSdkVersion": 12,
"runtimeOS": "OpenHarmony"

What is in the project directory?

PathPurpose
AppScope/app.json5Application-level configuration
entry/src/main/ets/entryabilityThe application entry point
entry/src/main/ets/pagesPage files, such as Index.ets
entry/src/main/resourcesImages, media, strings and layout resources
entry/src/main/module.json5Module configuration
entry/build-profile.json5Module build options
oh_modulesInstalled dependencies
hvigorfile.tsBuild script

What does Index.ets contain?

The template creates a page with a text and a button that navigates to a second page. The simplest version of it is:

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}

@Entry makes this page an entry, @Component declares a UI component, @State makes message reactive and build() describes the UI. Change 'Hello World' to your own text and run again to see the update. Details: What is ArkTS?.

How do I run the app?

  1. Connect a device (or start the emulator). To check that the device is visible, see the hdc command guide.
  2. For a physical device, enable automatic signing in File > Project Structure > SigningConfigs.
  3. Select the device in the toolbar and click the Run button.

Menu names can change between DevEco Studio versions, so use the official tutorial if a menu looks different.

Next steps

Frequently asked questions

Which project template should I choose for a first app?

Choose Application and then the Empty Ability template. This creates a Stage model project with a single page, Index.ets.

What is the Stage model?

The Stage model is the current application model used in DevEco Studio projects. Its entry point is in src/main/ets/entryability and its pages are in src/main/ets/pages.

Where is the app code?

Page code is in entry/src/main/ets/pages. A new project contains Index.ets with a Hello World page.

Do I need a physical device to run the app?

No. You can run it on a device or on the emulator that DevEco Studio supports. A physical device needs automatic signing to be enabled first.