DEV Community

Marxu
Marxu

Posted on

1

🔥 Getting Started with HarmonyOS 5.0+: Build Your First Cross-Device App(HarmonyOS 5.0.0 or high)

🔥 Getting Started with HarmonyOS 5.0+: Build Your First Cross-Device App

Want to build next-gen apps that run across phones, tablets, TVs, and more? HarmonyOS 5.0+ offers a powerful, distributed app model — and you can build your first app in minutes.


🚀 Why HarmonyOS?

HarmonyOS (鸿蒙) is Huawei’s next-gen OS designed for seamless device collaboration — from phones to wearables. With HarmonyOS 5.0+, you get:

  • ArkTS (modern TypeScript-based dev language)
  • Cross-device interaction
  • Lightning-fast startup & UI performance

🧰 Step 1: Environment Setup

  1. Download & install DevEco Studio 4.0+
  2. Create a new project:
  • App Template: Empty Feature Ability (Stage Model)
  • Language: ArkTS
    1. Select device: Phone

🛠️ Step 2: Hello HarmonyOS Code

File: entry/src/main/ets/pages/Index.ets

@Component
struct IndexPage {
  @State message: string = 'Welcome to HarmonyOS 5.0+!';

  build() {
    Column() {
      Text(this.message)
        .fontSize(26)
        .fontWeight(FontWeight.Bold)
        .margin(20)

      Button('Click Me')
        .onClick(() => {
          this.message = 'Hello, cross-device future!';
        })
        .margin(20)
    }
    .height('100%')
    .width('100%')
    .justifyContent(FlexAlign.Center)
    .alignItems(HorizontalAlign.Center)
  }
}
Enter fullscreen mode Exit fullscreen mode

📱 Step 3: Run and See

  • Click “Run” → choose an emulator or connected device
  • Initial screen shows: Welcome to HarmonyOS 5.0+!
  • Click the button → message updates to: Hello, cross-device future!

🖼️ Preview Result:

[ Welcome to HarmonyOS 5.0+! ]
[      Click Me Button       ] → [ Hello, cross-device future! ]
Enter fullscreen mode Exit fullscreen mode

❗ Common Pitfalls

Problem Reason Solution
App does not run Wrong SDK or build target Set build target to HarmonyOS 5.0.0+
Component doesn’t render Missing @Component decorator Add @Component before your struct
Button click has no effect Wrong event name (onTap, onClick) Use onClick only in ArkTS
Layout broken on device Column width/height not set Add .width('100%') and .height('100%')

📌 Summary

In under 10 minutes, you’ve:

  • Built your first HarmonyOS 5.0+ app
  • Understood ArkTS layout structure
  • Interacted with state via button click

🔮 What’s Next?

In the next post, we’ll explore ArkTS UI system in-depth and build a reusable counter component from scratch.

👉 Follow for more HarmonyOS magic. Comments welcome!

Heroku

Save time with this productivity hack.

See how Heroku MCP Server connects tools like Cursor to Heroku, so you can build, deploy, and manage apps—right from your editor.

Learn More

Top comments (0)

Redis image

Short-term memory for faster
AI agents

AI agents struggle with latency and context switching. Redis fixes it with a fast, in-memory layer for short-term context—plus native support for vectors and semi-structured data to keep real-time workflows on track.

Start building

👋 Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay