Development Environment
The official IDE for HarmonyOS is DevEco Studio, which, like Android Studio, is built upon the open-source IntelliJ IDEA Community Edition from JetBrains. The user interface is nearly identical to what Android developer are already familiar with.
Currantly, DevEco Studio only supports Windows; Mac users will need a Windows virtual machine. Once installed, the SDK can be downloaded directly without any special network configuration—a smoother experience compared to Android development in some regions.
Build System and Virtual Devices
Gradle serves as the build tool, exactly as in Android projects.
For running and debugging apps, there is no local emulator provided. Instead, you must register a Huawei developer account and add a remote virtual device through the Virtual Machine Manager.
Project Structure
entrydirectory – the default module, analogous to theappmodule in Android.entry/src/main/java– application source code, whilesrc/testholds unit tests, just like Android.entry/src/main/resource– resource directory, equivalent to Android’ssrc/main/res.entry/src/main/config.json– project and entry configuration, comparable toAndroidManifest.xml. It declares the package name, required system permissions, and the entry-point pages.
Core Concepts
- Ability: Similar to an Android
Activity. The default entry isMainAbility. - AbilitySlice: Comparable to a
Fragment; it manages the UI layout binding. - AbilityPackage: Analogous to the Android
Applicationclass, representing the entire application. - HVD (HarmonyOS Virtual Device): Like an AVD (Android Virtual Device), but accessed remotely.
- HAP (HarmonyOS Ability Package): The installation package extension, serving the same purpose as
.apkfiles in Android.
Code Examples
MainAbility (Activity)
package com.example.myharmonyapp;
import com.example.myharmonyapp.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
public class MainAbility extends Ability {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setMainRoute(MainAbilitySlice.class.getName());
}
}
AbilitySlice (Fragment equivalent)
package com.example.myharmonyapp.slice;
import com.example.myharmonyapp.data.UiHolder;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
public class MainAbilitySlice extends AbilitySlice {
private UiHolder uiHolder;
@Override
public void onStart(Intent intent) {
uiHolder = new UiHolder(this);
setUIContent(uiHolder.buildComponent());
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
Layout example: horizontal split
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:width="match_parent"
ohos:height="56vp"
ohos:orientation="horizontal">
<Text
ohos:id="$+id:left_label"
ohos:width="match_content"
ohos:height="match_content"
ohos:weight="1"
ohos:text_alignment="center"
ohos:text_size="16fp"
ohos:text="Left"
/>
<Text
ohos:id="$+id:right_label"
ohos:width="match_content"
ohos:height="match_content"
ohos:weight="1"
ohos:text_alignment="center"
ohos:text_size="16fp"
ohos:text="Right"
/>
</DirectionalLayout>
For Android developers, the learning curve for HarmonyOS is negligible. The API design shows clear Android influences, making the transition smooth. The platform offers a familiar structure and a friendly development experience.