skills/android-to-harmonyos-migration-workflow/SKILL.md
多 agent 协作的 Android 到 HarmonyOS 代码迁移工作流(迭代式)。当用户需要将 Android 项目迁移到 HarmonyOS 时触发,提供:1) Analyzer Agent 扫描代码结构 2) Planner Agent 制定迁移计划 3) Translator Agent 执行代码转换 4) **Validator Agent(验证代理)** 使用 **ohos-app-build-debug** skill 进行编译验证、应用打包和上板验证首界面 5) Tester Agent 验证功能(每个模块迁移完成后执行) 6) 所有模块迁移完成后,执行 Feature Comparator Agent 检查遗漏功能 7) UI Comparator Agent 验证界面一致性 8) 将未完成部分反馈给 Planner Agent 继续迭代。包含代码分析脚本、API映射表、组件转换模式和自动化验证工具。触发关键词:迁移Android到鸿蒙、Android迁移、HarmonyOS迁移、Java/Kotlin转ArkTS、Activity转Page、功能比对、UI比对。
npx skillsauth add openharmonyinsight/openharmony-skills android-to-harmonyos-migration-workflowInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
本技能提供系统化的 Android 到 HarmonyOS 代码迁移流程,使用 7 个专业 agent协作完成迁移任务。
用户提供源码和目标路径后,启动 Analyzer Agent
Planner Agent 制定初始迁移计划
模块迁移循环(逐个模块执行):
重复步骤 3,直到所有计划模块完成迁移
全局比对阶段(所有模块完成后):
┌─────────────────────────────────────────────────────────────────┐
│ Android 到 HarmonyOS 迁移工作流(迭代式) │
└─────────────────────────────────────────────────────────────────┘
┌──────────┐
│ Analyzer │ 扫描源码,生成结构报告
│ Agent │
└────┬─────┘
│
▼
┌──────────┐
│ Planner │ 制定初始迁移计划(模块清单、优先级)
│ Agent │
└────┬─────┘
│
▼
╔═══════════════════════════════════════════════════════════════╗
║ 模块迁移循环 ║
╠═══════════════════════════════════════════════════════════════╣
║ ║
║ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ║
║ │ Translator │───▶│ Validator │───▶│ Tester │ ║
║ │ Agent │ │ Agent │ │ Agent │ ║
║ │ 代码转换 │ │ 质量验证 │ │ 功能测试 │ ║
║ └──────────────┘ └──────────────┘ └──────┬───────┘ ║
║ │ ║
║ ▼ ║
║ ┌──────────────┐ ║
║ │ 模块完成 │ ║
║ │ 标记状态 │ ║
║ └──────┬───────┘ ║
║ │ ║
║ ┌────────┴────────┐ ║
║ │ │ ║
║ ▼ ▼ ║
║ 有更多模块? 所有模块完成 ║
║ │ │ ║
║ ▼ │ ║
║ ┌──────────────────┐ │ ║
║ │ 下一模块 N+1 │────────┘ ║
║ └────────┬─────────┘ ║
║ │ ║
╚═══════════════════════════════════════╪═══════════════════════╝
│ 所有模块完成
▼
╔═══════════════════════════════════════════════════════════════╗
║ 全局比对阶段 ║
╠═══════════════════════════════════════════════════════════════╣
║ ║
║ ┌─────────────────────────────────────────────────┐ ║
║ │ 比对阶段(并行执行) │ ║
║ ├────────────────────────────┬─────────────────────┤ ║
║ │ Feature Comparator │ UI Comparator │ ║
║ │ Agent │ Agent │ ║
║ │ 功能比对 │ UI 比对 │ ║
║ └─────────┬──────────────────┴────────────┬────────┘ ║
║ │ │ ║
║ └──────────┬────────────────────┘ ║
║ ▼ ║
║ ┌──────────────────┐ ║
║ │ 遗漏项收集 │ ║
║ │ (未完成功能/UI) │ ║
║ └────────┬─────────┘ ║
║ │ ║
╚════════════════════════╪═════════════════════════════════════╝
│
▼
┌──────────────────┐
│ Planner │◀────────┐
│ Agent │ │
│ 制定补充计划 │ │
└────────┬─────────┘ │
│ │
┌────────────────┴───────────────────┤
│ │
▼ ▼
有遗漏项? 无遗漏项
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ 迭代下一轮 │ │ 迁移完成 │
│ (回到模块循环) │ └──────────────┘
└──────────────┘
任务:扫描 Android 源码,生成代码结构报告
执行步骤:
# 运行分析脚本
python scripts/analyze.py <source-path>
输出:
任务:制定和更新模块化迁移计划(初始 + 迭代)
规划原则:
初始规划:模块清单和迁移检查清单
迭代规划(全局比对后触发):
详细规划方法:见 PLANNING.md
状态追踪:
migration_state:
iteration: 1 # 迭代轮次
completed_modules: []
in_progress: null
pending_modules:
- name: "数据层模块"
priority: 1
status: "pending"
missing_features: [] # 全局比对后填充
ui_differences: [] # 全局比对后填充
任务:执行代码转换
输入:来自 Planner Agent 的待迁移模块
转换映射:见 API_MAPPING.md
核心转换规则:
@Entry @Component Page@ComponentLazyForEach@Observed + @ObjectLink执行转换:
python scripts/migrate.py <source-file> <target-file> --mode <component-type>
输出:
任务:验证迁移质量
输入:来自 Translator Agent 的转换后代码
检查项:
执行验证:
使用 ohos-app-build-debug skill 进行编译验证、应用打包和上板验证首界面:
# 切换到项目目录
cd <project-path>
# 1. 编译验证(构建 HarmonyOS 应用)
python $SKILL_DIR/scripts/build.py
# 2. 应用打包(生成 HAP 安装包)
python $SKILL_DIR/scripts/install.py -f entry/build/default/outputs/default/entry-default-signed.hap
# 3. 上板验证首界面
python $SKILL_DIR/scripts/launch.py
# 4. 验证应用已启动
python $SKILL_DIR/scripts/screenshot.py -o ./screenshots/launched.png
如果需要更详细的调试或使用 DevEco Studio 内置工具:
# 设置 DevEco Studio 环境变量
set "HUAWEI_DEV_HOME=C:\Program Files\Huawei\DevEcoStudio"
set "PATH=%HUAWEI_DEV_HOME%\tools\hvigor\bin;%PATH%"
# 使用 hvigorw 编译
cd <project-path> && hvigorw assembleApp
# 安装 HAP
hdc install entry/build/default/outputs/default/entry-default-signed.hap
# 启动应用
hdc shell aa start -b <bundle-name> -a <ability-name>
输出:
任务:功能验证
输入:来自 Validator Agent 的已验证代码
测试清单:见 TESTING.md
输出:
任务:对比 Android 源码与迁移后的 HarmonyOS 代码,找出遗漏的功能
执行时机:所有模块迁移完成后执行(非每个模块后执行)
执行步骤:
# 运行功能比对脚本
python scripts/compare_features.py <android-source> <harmonyos-target>
比对维度:
输出:
详细比对方法:见 FEATURE_COMPARE.md
任务:比对 Android 和 HarmonyOS 应用的 UI 界面,确保视觉和交互一致性
执行时机:所有模块迁移完成后执行(非每个模块后执行)
执行步骤:
使用 Hypium 自动化框架启动应用并进行 UI 截图比对:
# 运行自动化 UI 比对脚本
迁移前Android 应用:
应用包名:com.simplemobiletools.gallery.pro
启动 Activity:com.simplemobiletools.gallery.pro.activities.SplashActivity.Orange
迁移后鸿蒙 应用:
应用包名:com.example.myapplication
启动 Activity:EntryAbility
python scripts/compare_ui_auto.py --android <android-package> --harmonyos <harmonyos-package>
# 运行 UI 比对脚本
python scripts/compare_ui.py <android-screenshots-dir> <harmonyos-screenshots-dir>
# 或比对布局文件
python scripts/compare_ui.py --layout <android-xml-dir> <harmonyos-ets-dir>
比对维度:
输入要求: | 输入类型 | Android | HarmonyOS | |----------|---------|-----------| | 应用包名 | com.simplemobiletools.gallery.pro | com.example.myapplication | | 启动 Activity | com.simplemobiletools.gallery.pro.activities.SplashActivity.Orange | EntryAbility | | 截图 | PNG/JPG 文件 | PNG/JPG 文件 | | 布局文件 | XML (res/layout/) | ETS (@Component) | | 样式文件 | styles.xml | 主题配置 |
比对维度:
输出:
详细比对方法:见 UI_COMPARE.md
| 文档 | 用途 | 何时读取 | |------|------|----------| | API_MAPPING.md | Android/HarmonyOS API 对照表 | 执行转换时 | | COMPONENT_MAPPING.md | 组件转换模式 | 转换 UI 组件时 | | COMMON_PATTERNS.md | 常见代码模式转换 | 遇到特定模式时 | | TROUBLESHOOTING.md | 问题排查指南 | 出现错误时 | | FEATURE_COMPARE.md | 功能比对方法和检查项 | 功能比对时 | | UI_COMPARE.md | UI比对方法和检查项 | UI比对时 |
C:\xxj\code\Simple-Gallery-masterC:\workspace\0210C:\xxj\code\docsC:\xxj\code\zh-cn\application-dev┌─────────────────────────────────────────────────────────────────┐
│ 模块迁移循环 │
│ (逐个处理所有计划模块) │
└─────────────────────────────────────────────────────────────────┘
模块N ──▶ Translator ──▶ Validator ──▶ Tester ──▶ 模块完成 ✓
Agent Agent Agent
(代码转换) (质量验证) (功能测试)
│
┌─────────┴─────────┐
▼ ▼
有更多模块? 所有模块完成
│ │
▼ │
┌──────────┐ │
│ 模块N+1 │ │
└──────────┘ │
│ │
└───────────────────┘
│ 所有模块完成
▼
┌──────────────────────────┐
│ 进入全局比对阶段 │
└──────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ 全局比对阶段 │
│ (所有模块迁移完成后执行一次) │
└─────────────────────────────────────────────────────────────────┘
Feature Comparator ──┐
Agent │ 并行执行
├──▶ 遗漏项收集 ──▶ Planner Agent ──┬─▶ 有遗漏项?
UI Comparator ──────┘ (合并) (制定补充计划) │
Agent │
▼
┌──────────────────┐
│ 回到模块迁移循环 │
│ 处理遗漏项模块 │
└──────────────────┘
│
┌────────────────────────┴────────┐
▼ ▼
有遗漏项? 无遗漏项
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ 继续迭代 │ │ 迁移完成 │
│ (下一轮) │ └──────────────┘
└──────────────┘
迁移工作完成需满足以下所有条件:
| 检查项 | 标准 | 负责代理 | |--------|------|----------| | 代码转换率 | 100% 文件已转换 | Translator Agent | | 语法验证 | 0 错误,< 10 警告 | Validator Agent | | 编译状态 | 编译通过 | Validator Agent | | 功能测试 | 核心功能 100% 通过 | Tester Agent | | 功能覆盖率 | ≥ 95% | Feature Comparator Agent | | UI 一致性 | 核心页面 100% 匹配 | UI Comparator Agent | | 性能对比 | 响应时间差异 < 20% | Tester Agent |
每次迭代后,Planner Agent 更新 migration_status.yaml:
# migration_status.yaml
project:
name: "SimpleGallery"
source: "C:\\xxj\\code\\Simple-Gallery-master"
target: "C:\\workspace\\0210"
# 迭代信息
iteration:
current: 2 # 当前迭代轮次
phase: "module_migration" # 模块迁移阶段 | 全局比对阶段
overall_progress:
total_modules: 8
completed_modules: 3
in_progress: "数据模型模块"
completion_percentage: 37.5%
modules:
- name: "数据模型模块"
status: "completed"
files:
- "Photo.ets ✓"
- "Album.ets ✓"
issues: []
- name: "数据访问层模块"
status: "completed"
files:
- "PhotoRepository.ets ✓"
- "AlbumRepository.ets ✓"
issues: []
- name: "业务逻辑层模块"
status: "in_progress"
files:
- "MainViewModel.ets ⚠ (部分API未实现)"
- "SettingsViewModel.ets ✓"
issues:
- type: "missing_api"
description: "批量删除API未实现"
priority: "high"
- name: "UI层模块"
status: "pending"
files: []
# 全局比对结果(所有模块完成后填充)
global_comparison:
status: "pending" # pending | in_progress | completed
missing_features:
- feature: "照片批量删除"
module: "业务逻辑层模块"
priority: "high"
found_by: "Feature Comparator Agent"
status: "待实现"
- feature: "照片分享功能"
module: "业务逻辑层模块"
priority: "medium"
found_by: "Feature Comparator Agent"
status: "待实现"
ui_differences:
- page: "MainPage"
differences:
- type: "missing_component"
description: "缺少滑动删除手势"
priority: "medium"
found_by: "UI Comparator Agent"
status: "待修复"
last_update: "2026-02-07T17:15:00"
next_step: "继续迁移 业务逻辑层模块"
development
Run local code quality checks covering a subset of OpenHarmony gate CI (copyright, CodeArts C/C++) plus additional local checks (pylint/flake8, shellcheck/bashate, gn format). Use before committing to reduce gate failures. Triggers on: /oh-precommit-codecheck, "门禁检查", "门禁预检", "检查代码", "run codecheck", "check code quality", "lint my code", "代码检查", or after completing code implementation. WHEN to use: before git commit, before creating PR, after modifying C/C++/Python/Shell/GN files, when gate CI fails with codecheck defects, or when you want to preview what gate will flag.
development
OpenHarmony PR full lifecycle workflow. Five modes: - Commit: standardized commit with DCO sign-off and Issue linking - Create PR: commit + push to fork + create Issue + create PR on upstream - Fix Codecheck: fetch gate CI codecheck defects from a PR and auto-fix them - Review PR: fetch a PR's changes to local for code review - Fix Review: fetch unresolved review comments from a PR and auto-fix them Triggers on: /oh-pr-workflow, "提交代码", "创建PR", "提个PR", "commit", "修复告警", "修复门禁", "修复codecheck", "fix codecheck", "review pr", "review这个pr", "看下这个pr", "检视pr", "修复review", "修复检视意见", "fix review", or a GitCode PR URL with fix/review intent.
testing
分析 HM Desktop PRD 文档,提取需求信息、验证完整性、检查章节顺序(需求来源→需求背景→需求价值分析→竞品分析→需求描述)、检查 KEP 定义、检测需求冲突并生成结构化分析报告。适用于用户请求:(1) 分析或审查 PRD 文档, (2) 从需求中提取 KEP 列表, (3) 检查 PRD 完整性或一致性, (4) 将需求映射到模块架构, (5) 验证 PRD 格式合规性, (6) 验证竞品分析章节完整性。关键词:PRD分析, requirement extraction, KEP验证, completeness check, chapter order validation, 竞品分析检查, analyze PRD, 需求提取, 完整性检查, 章节顺序验证
development
基于 PRD 文档自动生成鸿蒙系统设计文档,包括架构设计文档和功能设计文档。生成前会分析 OpenHarmony 存量代码结构,确保与现有架构兼容。架构设计文档第2章必须为竞品方案分析,位于需求背景之后。适用于用户请求:(1) 生成架构设计文档, (2) 生成功能设计文档, (3) 从 PRD 生成设计文档, (4) 创建系统架构设计, (5) 编写功能规格说明, (6) 分析 OH 代码结构。关键词:architecture design, functional design, design doc, 竞品方案分析, OpenHarmony code analysis, 架构设计, 功能设计, 设计文档生成, OH代码分析, analyze codebase, competitor analysis