arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2606.07085cs.SE
收藏

将声明式UI移植到鸿蒙:一种启发式引导的LLM方法

Porting Declarative UI to HarmonyOS: A Heuristic-guided Approach for lightweight LLMs

Shandong University(山东大学);University Of Jinan(济南大学);Tianjin University(天津大学);University of Glasgow(格拉斯哥大学);Peking University(北京大学)

Kunwu Zheng, Pengyu Xue, Zhen Yang, Tianlong Chen, Xiran Lyu, Peishi Lai, Mengying Zhao, Junjie Chen, Yutian Tang, Huizhi Zhang, Xianhang Li, Linhao Wu, Chengyi Wang

AI总结:

针对鸿蒙系统从Android/iOS迁移声明式UI的需求,提出ArkTrans方法,通过启发式构建骨架和模式匹配修复语法错误,实现高编译成功率和视觉保真度。

摘要:

作为一个新兴操作系统,鸿蒙对从Android和iOS等平台进行软件迁移有显著需求,其中用户界面(UI)翻译是关键环节。然而,最新的UI开发已转向声明式范式,例如Android的Kotlin Jetpack Compose(KJC)、iOS的SwiftUI和鸿蒙的ArkUI,这使得先前的翻译方法不再适用,因为它们要么针对后端逻辑,要么针对传统的命令式UI。因此,本文针对ArkUI提出了一种自动翻译方法,名为ArkTrans,用于将UI文件从Android和iOS移植到鸿蒙。ArkTrans克服了翻译过程中的两个突出挑战:(1)编程语言(PL)不熟悉,以及(2)严重的语法混乱。针对第一个挑战,ArkTrans通过从源PL提取元数据启发式地构建ArkUI骨架,从而指导LLM的初始翻译。针对第二个挑战,ArkTrans通过模式匹配执行经验揭示的后修复规则,以修复大部分剩余的语法错误。为了检验ArkTrans的有效性,我们在文件级别构建了一个包含100个样本的从KJC/SwiftUI到ArkUI的并行UI页面翻译基准。大量实验表明,直接/一次性提示的LLM无法翻译出一个可编译的UI页面。相比之下,最多90.67%的ArkTrans翻译文件可以成功编译,并具有高视觉保真度。

英文摘要:

As an emerging operating system, HarmonyOS has a significant demand for software migration, where the User Interface (UI) translation accounts for a critical link. However, recent UI development has shifted to declarative paradigms, e.g., Kotlin Jetpack Compose (KJC) for Android, SwiftUI for iOS, and ArkUI for HarmonyOS, making prior translation approaches inapplicable because they target either backend logic or legacy imperative UIs. Thus, related research is limited. To systematically evaluate KJC/SwiftUI-to-ArkUI migration, we build a parallel benchmark of 100 KJC and 100 SwiftUI files across eight scenarios, plus 52 real-world UI pages from nine open-source apps. Evaluating nine direct-translation setups (including diverse LLMs and agents), we find Compilation Success Rate (CSR) spans 0.00%-35.00%; common strategies (reference screenshots and compiler-guided repair) lift capable setups to 94.00%-99.00% CSR but fail on lightweight LLMs. By manually analyzing a 3,102-sample subset, deriving a regular-expression pattern for each failure family, and applying these patterns to generalize the resulting taxonomy to the full 29,593-sample set, we find residual errors rooted in (1) broken structure, (2) nonexistent APIs, and (3) missing resources (e.g., colors, strings, and icons). Accordingly, we propose ArkTrans, a declarative UI translation framework that maps these roots to deterministic structure supply, ArkUI knowledge and resource reference injection via a demonstration example, and iterative repair targeting residual errors, via four steps: Metadata Extraction, Skeleton Construction, LLM-driven Translation, and Compiler-Guided Iterative Repair. With Qwen3.6-27B, ArkTrans raises CSR from 0.00% to 70.00% on KJC and 64.00% on SwiftUI, achieving strong visual fidelity, and attains 65.63%/80.00% CSR on real-world pages, far outperforming the best common strategy at lower token cost.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑