HarmonyOS NEXT 系统梳理
HarmonyOS NEXT(鸿蒙星河版)是完全自研的国产操作系统,彻底剥离 AOSP,不再兼容 Android APK,仅支持 ArkTS 原生应用。搭载自研鸿蒙内核替代 Linux Kernel,ArkCompiler 取代 ART 虚拟机,采用声明式 ArkUI 框架和 Stage 应用模型。
与旧版关键区别:
- 内核:自研鸿蒙内核(微内核架构,非 Linux)
- 运行时:ArkCompiler + 方舟运行时(GC 代数分代,无 JIT)
- 应用:仅原生 ArkTS App,不支持 Android APK
- UI:ArkUI 声明式框架,非 Android View 体系
- 应用模型:Stage 模型(UIAbility + ExtensionAbility),完全取代 FA/PA
- 编译:AOT 编译为 ark 字节码,启动速度 3x+ 提升
1. 概述
HarmonyOS NEXT 的核心理念是"一次开发,多端部署",通过分层架构和组件化设计,覆盖手机、平板、智慧屏、车机、穿戴等设备形态。系统采用微内核设计,仅包含最基础的进程调度、IPC、内存管理等原语,其余皆为用户态服务。
技术自主性
- 自研鸿蒙内核(HM Kernel)
- 自研 ArkCompiler 编译器/运行时
- 自研 ArkUI 声明式 UI 引擎
- 自研 ArkData 分布式数据服务
- 自研 HDF 硬件驱动框架
核心特性
- 原生精致:ArkUI 全新视觉体验
- 原生易用:统一交互范式
- 原生流畅:端云一体,极简连接
- 原生安全:星盾安全架构
- 原生智能:盘古大模型内置
- 原生互联:6 大能力开放
图:HarmonyOS NEXT 核心技术全景
2. 行为图
2.1 用例图
图:HarmonyOS NEXT 用户与开发者用例图
2.2 活动图 — App 启动流程
HarmonyOS NEXT App 启动时,ArkCompiler 直接执行 AOT 编译好的 ark 字节码,无需 JIT 预热。
图:HarmonyOS NEXT 应用冷启动活动图
2.3 活动图 — 跨设备流转
图:应用跨设备流转活动图(带泳道)
2.4 状态机图 — UIAbility 生命周期
Stage 模型下,UIAbility 替代旧版 PageAbility,生命周期更明确。
图:UIAbility 生命周期状态机
2.5 序列图 — 分布式软总线通信
图:分布式软总线 — 设备发现与数据传输序列图
3. 结构图
3.1 包图 — 系统分层
图:HarmonyOS NEXT 分层架构包图
3.2 组件图 — 核心子系统
图:HarmonyOS NEXT 核心子系统组件图
3.3 类图 — Stage 应用模型
Stage 模型是 HarmonyOS NEXT 唯一的应用模型,核心包含 UIAbility、ExtensionAbility、AbilityStage。
图:Stage 模型核心类图
3.4 部署图 — 设备拓扑
图:超级终端 — 鸿蒙生态多设备融合部署图
4. 使用手册
4.1 环境搭建
| 步骤 | 操作 |
|---|---|
| 1 | 下载 DevEco Studio(NEXT 专用版) |
| 2 | 安装 HarmonyOS NEXT SDK(API 12+) |
| 3 | 申请设备调试权限(需登录华为开发者帐号) |
| 4 | 连接 HarmonyOS NEXT 真机或使用模拟器 |
| 5 | 创建 Stage 模型项目模板,开始开发 |
4.2 ArkTS 声明式 UI
ArkTS 是面向 HarmonyOS NEXT 的 TypeScript 超集,融合声明式 UI 语法和状态管理。
// 带状态管理的 ArkUI 页面
@Entry
@Component
struct CounterPage {
@State count: number = 0
build() {
Column({ space: 20 }) {
Text(`计数: ${this.count}`)
.fontSize(48)
.fontWeight(FontWeight.Bold)
Row({ space: 16 }) {
Button('-')
.width(60).height(60)
.fontSize(30)
.onClick(() => this.count--)
Button('+')
.width(60).height(60)
.fontSize(30)
.onClick(() => this.count++)
}
Button('重置')
.onClick(() => this.count = 0)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
}
关键装饰器:
- @Entry — 标记为页面入口
- @Component — 声明自定义组件
- @State — 组件内状态,变化自动触发 UI 更新
- @Prop — 父→子单向同步
- @Link — 父↔子双向同步
- @Provide / @Consume — 跨组件层级共享状态
- @StorageLink / @StorageProp — AppStorage 全局状态绑定
4.3 Stage 模型
Stage 模型是 NEXT 唯一应用模型,一个应用由一个 AbilityStage(全局)和多个 UIAbility / ExtensionAbility 组成。
UIAbility
- 带 UI 的用户交互能力
- 核心生命周期:onCreate → onWindowStageCreate → onForeground → onBackground → onDestroy
- 通过 Want 启动
ExtensionAbility
- 无 UI 的扩展能力
- Service Ext. — 后台服务
- Form Ext. — 桌面卡片
- InputMethod Ext. — 输入法
- Window Ext. — 跨应用窗口
AbilityStage
- 应用级生命周期入口
- onCreate() — 应用创建时
- onAcceptWant() — 接收跨设备 Want
- onConfigurationUpdate() — 配置变更
// Stage 模型入口
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate(): void {
Hilog.info(0x0000, 'MyApp', 'AbilityStage onCreate');
}
}
// module.json5 配置
{
"module": {
"name": "entry",
"type": "entry",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ets",
"launchType": "singleton",
"skills": [
{
"entities": ["entity.system.home"],
"actions": ["action.system.home"]
}
]
}
],
"extensionAbilities": [
{
"name": "FormExtAbility",
"srcEntry": "./ets/formability/FormExtAbility.ets",
"type": "form"
}
]
}
}
4.4 分布式开发
| 能力 | 模块 (NEXT) | 用途 |
|---|---|---|
| 设备发现与认证 | @ohos.distributedDeviceManager | 发现附近设备、建立可信连接 |
| 分布式 KV 存储 | @ohos.data.distributedKVStore | 跨设备键值对自动同步 |
| 跨设备迁移 | @ohos.ability.wantConstant | 通过 Want 参数跨设备启动 UIAbility |
| 分布式拖拽 | @ohos.arkui.dragController | 跨设备拖拽交互 |
| 服务卡片 | formProvider | 跨设备显示和更新桌面卡片 |
// 跨设备启动 UIAbility
import Want from '@ohos.app.ability.Want';
const want: Want = {
deviceId: 'targetDeviceId',
bundleName: 'com.example.app',
abilityName: 'EntryAbility'
};
this.context.startAbility(want).then(() => {
console.info('跨设备启动成功');
}).catch((err) => {
console.error('跨设备启动失败: ' + JSON.stringify(err));
});
// 分布式 KV 同步
import distributedKVStore from '@ohos.data.distributedKVStore';
const manager = distributedKVStore.createKVManager({
bundleName: 'com.example.app'
});
const options: distributedKVStore.Options = {
createIfMissing: true,
encrypt: false,
autoSync: true, // 自动同步
backup: false,
kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION
};
manager.getKVStore('storeId', options).then((store) => {
store.put('theme', 'dark').then(() => {
console.info('主题偏好已同步到所有设备');
});
});