As an emerging operating system, HarmonyOS has a significant demand for software migration from platforms such as Android and iOS, where the User Interface (UI) translation accounts for a critical link. However, the latest UI development has shifted to declarative paradigms, e.g., Kotlin Jetpack Compose (KJC) for Android, SwiftUI for iOS, and ArkUI for HarmonyOS, rendering prior translation approaches inapplicable, as they target either backend logic or legacy imperative UIs. As such, this paper targets ArkUI and proposes an automatic translation approach, namely ArkTrans, to port UI files from Android and iOS to HarmonyOS. ArkTrans overcomes two salient challenges during the translation: (1) Programming Language (PL) unfamiliarity, and (2) severe syntactic chaos. Towards the first challenge, ArkTrans heuristically constructs ArkUI skeletons by extracting metadata from source PL, thereby guiding LLMs' initial translation. As for the second challenge, ArkTrans executes empirically revealed post-fixing rules via pattern matching to repair most of the remaining syntactic errors. To examine the effectiveness of ArkTrans, we construct a 100-sample parallel UI page translation benchmark from KJC/SwiftUI to ArkUI at the file level. Extensive experiments demonstrate that LLMs with direct/one-shot prompting cannot translate a single compilable UI page. In contrast, at most 90.67\% ArkTrans-translated files can be successfully compiled with high visual fidelity.
翻译:作为新兴操作系统,鸿蒙系统对来自安卓和iOS等平台的软件迁移需求显著,其中用户界面(UI)转换是至关重要的环节。然而,最新的UI开发已转向声明式范式(例如安卓的Kotlin Jetpack Compose、iOS的SwiftUI以及鸿蒙的ArkUI),导致先前的转换方法不再适用——这些方法要么针对后端逻辑,要么针对传统的命令式UI。为此,本文聚焦ArkUI,提出名为ArkTrans的自动化转换方法,用于将安卓和iOS的UI文件移植到鸿蒙系统。ArkTrans克服了转换过程中的两大挑战:(1)编程语言(PL)不熟悉性;(2)严重的语法混乱。针对第一个挑战,ArkTrans通过从源PL中提取元数据启发式地构建ArkUI骨架,从而引导大语言模型进行初始转换。针对第二个挑战,ArkTrans通过模式匹配执行基于经验揭示的后期修复规则,以修复大部分剩余语法错误。为验证ArkTrans的有效性,我们构建了包含100个样本的并行UI页面转换基准测试集(从KJC/SwiftUI到ArkUI,文件级别)。大量实验表明,使用直接/单次提示的大语言模型无法转换出任何可编译的UI页面。相比之下,ArkTrans转换的文件中最多有90.67%可成功编译,且视觉保真度高。