This skill provides a systematic Android to HarmonyOS code migration process, using 7 specialized agentsto collaboratively complete the migration task.
Quick Start
-
After the user provides the source code and target path, start Analyzer Agent
-
Planner Agent to formulate the initial migration plan
-
Module migration loop(execute module by module):
- Select a module → Translator Agent converts the code
- → Validator Agent uses the ohos-app-build-debug skill to perform compilation verification, app packaging, and on-device verification of the first screen
- → Tester Agent tests functionality
- → mark the module as completed, continue to the next module
-
Repeat step 3,until all planned modules have completed migration
- Global comparison stage(after all modules are completed):
- Feature Comparator Agent compare for missed functionality
- UI Comparator Agent compare the UI
- → feed back unfinished items to Planner Agent
- Iteration loop:
- The Planner Agent formulates a supplementary migration plan based on the comparison results
- Repeat steps 3-5 until there are no missed items
Workflow
┌─────────────────────────────────────────────────────────────────┐
│ Android 到 HarmonyOS 迁移工作流(迭代式) │
└─────────────────────────────────────────────────────────────────┘
┌──────────┐
│ Analyzer │ 扫描源码,生成结构报告
│ Agent │
└────┬─────┘
│
▼
┌──────────┐
│ Planner │ 制定初始迁移计划(模块清单、优先级)
│ Agent │
└────┬─────┘
│
▼
╔═══════════════════════════════════════════════════════════════╗
║ 模块迁移循环 ║
╠═══════════════════════════════════════════════════════════════╣
║ ║
║ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ║
║ │ Translator │───▶│ Validator │───▶│ Tester │ ║
║ │ Agent │ │ Agent │ │ Agent │ ║
║ │ 代码转换 │ │ 质量验证 │ │ 功能测试 │ ║
║ └──────────────┘ └──────────────┘ └──────┬───────┘ ║
║ │ ║
║ ▼ ║
║ ┌──────────────┐ ║
║ │ 模块完成 │ ║
║ │ 标记状态 │ ║
║ └──────┬───────┘ ║
║ │ ║
║ ┌────────┴────────┐ ║
║ │ │ ║
║ ▼ ▼ ║
║ 有更多模块? 所有模块完成 ║
║ │ │ ║
║ ▼ │ ║
║ ┌──────────────────┐ │ ║
║ │ 下一模块 N+1 │────────┘ ║
║ └────────┬─────────┘ ║
║ │ ║
╚═══════════════════════════════════════╪═══════════════════════╝
│ 所有模块完成
▼
╔═══════════════════════════════════════════════════════════════╗
║ 全局比对阶段 ║
╠═══════════════════════════════════════════════════════════════╣
║ ║
║ ┌─────────────────────────────────────────────────┐ ║
║ │ 比对阶段(并行执行) │ ║
║ ├────────────────────────────┬─────────────────────┤ ║
║ │ Feature Comparator │ UI Comparator │ ║
║ │ Agent │ Agent │ ║
║ │ 功能比对 │ UI 比对 │ ║
║ └─────────┬──────────────────┴────────────┬────────┘ ║
║ │ │ ║
║ └──────────┬────────────────────┘ ║
║ ▼ ║
║ ┌──────────────────┐ ║
║ │ 遗漏项收集 │ ║
║ │ (未完成功能/UI) │ ║
║ └────────┬─────────┘ ║
║ │ ║
╚════════════════════════╪═════════════════════════════════════╝
│
▼
┌──────────────────┐
│ Planner │◀────────┐
│ Agent │ │
│ 制定补充计划 │ │
└────────┬─────────┘ │
│ │
┌────────────────┴───────────────────┤
│ │
▼ ▼
有遗漏项? 无遗漏项
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ 迭代下一轮 │ │ 迁移完成 │
│ (回到模块循环) │ └──────────────┘
└──────────────┘
1. Analyzer Agent
Task: scan the Android source code and generate a code structure report
Execution steps:
# 运行分析脚本
python scripts/analyze.py <source-path>
Output:
- File statistics (total count, language distribution)
- Component type distribution (Activity, Fragment, Service, etc.)
- Dependency graph
- Complexity score
2. Planner Agent
Task: formulate and update the modular migration plan (initial + iterative)
Planning principles:
- Each module is about 5000 lines of code
- Migration order: data layer → business logic → UI layer
- Prioritize migrating low-risk, highly reusable modules
Initial planning: module list and migration checklist
Iterative planning(triggered after global comparison):
- Receive the list of missed functionality from the Feature Comparator Agent
- Receive the UI difference list from the UI Comparator Agent
- Formulate a supplementary migration plan (missed items as new modules)
- Dynamically adjust the priority of modules to be migrated
- Track overall migration progress
Detailed planning method: see PLANNING.md
Status tracking:
migration_state:
iteration: 1 # 迭代轮次
completed_modules: []
in_progress: null
pending_modules:
- name: "数据层模块"
priority: 1
status: "pending"
missing_features: [] # 全局比对后填充
ui_differences: [] # 全局比对后填充
3. Translator Agent
Task: execute code conversion
Input: modules to be migrated from the Planner Agent
Conversion mapping: see API_MAPPING.md
Core conversion rules:
- Activity →
@Entry @ComponentPage - Fragment →
@Component - RecyclerView →
LazyForEach - Room → RelationalDB
- ViewModel →
@Observed + @ObjectLink
Execute conversion:
python scripts/migrate.py <source-file> <target-file> --mode <component-type>
Output:
- Converted ArkTS code files
- Conversion report (success/failure/warning)
- Pass to the Validator Agent for quality checking
4. Validator Agent
Task: Verify migration quality
Input: Converted code from the Translator Agent
Check items:
- ArkTS syntax compliance
- API version <= 22
- No compilation errors
- Type safety
Execute validation:
Method 1: Use the ohos-app-build-debug skill (recommended)
Use the ohos-app-build-debug skill for compilation validation, app packaging, and on-device validation of the first screen:
# 切换到项目目录
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
Method 2: Use the native DevEco Studio tool (alternative)
If more detailed debugging is needed or you want to use the built-in tools of 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>
Output:
- Validation report (pass/fail/warning)
- Issue list (items to be fixed)
- If passed, pass to the Tester Agent; if failed, return to the Translator Agent for fixing
5. Tester Agent
Task: Functional verification
Input: Verified code from the Validator Agent
Test list: See TESTING.md
Output:
- Functional test report
- Test case pass rate
- List of failed cases
- The module is marked as completed, continue to the next module
- After all modules are completed, trigger the Feature Comparator Agent and the UI Comparator Agent for global comparison
6. Feature Comparator Agent
Task: Compare the Android source code with the migrated HarmonyOS code to find missing features
Execution timing:Execute after all modules are migrated(not after each module)
Execution steps:
# 运行功能比对脚本
python scripts/compare_features.py <android-source> <harmonyos-target>
Comparison dimensions:
- Feature list comparison: Scan the Activity, Fragment, Service, and BroadcastReceiver in the Android source code, and compare them with the corresponding implementations in HarmonyOS
- API call coverage: Check whether the system APIs used in Android all have corresponding implementations in HarmonyOS
- Business logic completeness: Compare whether the core business classes and methods have been completely migrated
- Resource file coverage: Check whether resources such as strings, images, and layouts have been completely migrated
Output:
- Feature coverage report (migrated/total)
- List of missing features (with priority annotations)
- List of partially migrated features (content that needs to be supplemented)
- Incomplete items fed back to the Planner Agent for formulating the next round of supplementary migration plans
Detailed comparison method: See FEATURE_COMPARE.md
7. UI Comparator Agent
Task: Compare the UI screens of the Android and HarmonyOS apps to ensure visual and interaction consistency
Execution timing:Execute after all modules are migrated(not after each module)
Execution steps:
Method 1: Automated UI comparison (recommended)
Use the Hypium automation framework to launch the app and perform UI screenshot comparison:
# 运行自动化 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>
Method 2: Manual screenshot comparison
# 运行 UI 比对脚本
python scripts/compare_ui.py <android-screenshots-dir> <harmonyos-screenshots-dir>
# 或比对布局文件
python scripts/compare_ui.py --layout <android-xml-dir> <harmonyos-ets-dir>
Comparison Dimensions:
- Layout Structure: Page hierarchy structure, component arrangement
- Visual Style: Colors, fonts, spacing, corner radius, shadows
- Size Adaptation: Display effects at different screen sizes
- Interactive Elements: Consistency of interactive components such as buttons, input fields, lists, etc.
- Animation Effects: Transition animations, loading animations, etc.
Input Requirements:
| Input Type | Android | HarmonyOS |
|---|---|---|
| App Package Name | com.simplemobiletools.gallery.pro | com.example.myapplication |
| Launch Activity | com.simplemobiletools.gallery.pro.activities.SplashActivity.Orange | EntryAbility |
| Screenshot | PNG/JPG File | PNG/JPG File |
| Layout File | XML (res/layout/) | ETS (@Component) |
| Style File | styles.xml | Theme Configuration |
Comparison Dimensions:
- Layout Structure: Page hierarchy structure, component arrangement
- Visual Style: Colors, fonts, spacing, corner radius, shadows
- Size Adaptation: Display effects at different screen sizes
- Interactive Elements: Consistency of interactive components such as buttons, input fields, lists, etc.
- Animation Effects: Transition animations, loading animations, etc.
- Interaction Behavior: Simulate user operations through Hypium to verify consistency of interaction responses
Output:
- UI difference heatmap (marking difference locations)
- Layout difference report (missing/extra components)
- Style difference list (colors, fonts, spacing, etc.)
- Interaction difference description
- UI incomplete items fed back to the Planner Agent, used to formulate the next round of supplementary migration plan
- Fix suggestions and priorities
Detailed Comparison Method: See UI_COMPARE.md
Reference Documents
| Document | Purpose | When to Read |
|---|---|---|
| API_MAPPING.md | Android/HarmonyOS API Comparison Table | When performing conversion |
| COMPONENT_MAPPING.md | Component Conversion Patterns | When converting UI components |
| COMMON_PATTERNS.md | Common Code Pattern Conversion | When encountering specific patterns |
| TROUBLESHOOTING.md | Troubleshooting Guide | When errors occur |
| FEATURE_COMPARE.md | Function Comparison Methods and Check Items | When comparing functions |
| UI_COMPARE.md | UI Comparison Methods and Check Items | When comparing UI |
Current Project Configuration
- Source Code Path:
C:\xxj\code\Simple-Gallery-master - Target Path:
C:\workspace\0210 - API Restrictions:<= API 22
- HarmonyOS Syntax Reference Document:
C:\xxj\code\docs - HarmonyOS API Interface Reference Document:
C:\xxj\code\zh-cn\application-dev
Iteration Loop Summary
Phase One: Module Migration Loop
┌─────────────────────────────────────────────────────────────────┐
│ 模块迁移循环 │
│ (逐个处理所有计划模块) │
└─────────────────────────────────────────────────────────────────┘
模块N ──▶ Translator ──▶ Validator ──▶ Tester ──▶ 模块完成 ✓
Agent Agent Agent
(代码转换) (质量验证) (功能测试)
│
┌─────────┴─────────┐
▼ ▼
有更多模块? 所有模块完成
│ │
▼ │
┌──────────┐ │
│ 模块N+1 │ │
└──────────┘ │
│ │
└───────────────────┘
│ 所有模块完成
▼
┌──────────────────────────┐
│ 进入全局比对阶段 │
└──────────────────────────┘
Phase Two: Global Comparison Loop
┌─────────────────────────────────────────────────────────────────┐
│ 全局比对阶段 │
│ (所有模块迁移完成后执行一次) │
└─────────────────────────────────────────────────────────────────┘
Feature Comparator ──┐
Agent │ 并行执行
├──▶ 遗漏项收集 ──▶ Planner Agent ──┬─▶ 有遗漏项?
UI Comparator ──────┘ (合并) (制定补充计划) │
Agent │
▼
┌──────────────────┐
│ 回到模块迁移循环 │
│ 处理遗漏项模块 │
└──────────────────┘
│
┌────────────────────────┴────────┐
▼ ▼
有遗漏项? 无遗漏项
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ 继续迭代 │ │ 迁移完成 │
│ (下一轮) │ └──────────────┘
└──────────────┘
Complete Iteration Process Description
- Initial Planning: The Planner Agent analyzes the source code and formulates a modular migration plan
- Module Migration Loop:
- Execute in sequence for each module: Translator → Validator → Tester
- After completing a module, mark it as completed and continue to the next one
- Until all planned modules are migrated
- Global comparison:
- After all modules are completed, run the Feature Comparator and UI Comparator
- Collect missed features and UI differences
- Iteration decision:
- If there are missed items: the Planner Agent formulates a supplementary plan and returns to step 2
- If there are no missed items: migration is complete
Completion criteria
The migration work is complete only when all of the following conditions are met:
| Check item | Criteria | Responsible agent |
|---|---|---|
| Code conversion rate | 100% of files converted | Translator Agent |
| Syntax validation | 0 errors, < 10 warnings | Validator Agent |
| Compilation status | Compilation passes | Validator Agent |
| Functional testing | Core functionality 100% passing | Tester Agent |
| Feature coverage | ≥ 95% | Feature Comparator Agent |
| UI consistency | Core pages 100% matching | UI Comparator Agent |
| Performance comparison | Response time difference < 20% | Tester Agent |
Status file format
After each iteration, the Planner Agent updates 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: "继续迁移 业务逻辑层模块"