A Rule-Based Approach for UI Migration from Android to iOS

Yi Gao, Xing Hu, Tongtong Xu, Xin Xia, Xiaohu YangarXiv 2024 · DOI

Abstract

In the mobile development process, creating the user interface (UI) is highly resource intensive. Consequently, numerous studies have focused on automating UI development, such as generating UI from screenshots or design specifications. However, they heavily rely on computer vision techniques for image recognition. Any recognition errors can cause invalid UI element generation, compromising the effectiveness of these automated approaches. Moreover, developing an app UI from scratch remains a time consuming and labor intensive task. To address this challenge, we propose a novel approach called GUIMIGRATOR, which enables the cross platform migration of existing Android app UIs to iOS, thereby automatically generating UI to facilitate the reuse of existing UI. This approach not only avoids errors from screenshot recognition but also reduces the cost of developing UIs from scratch. GUIMIGRATOR extracts and parses Android UI layouts, views, and resources to construct a UI skeleton tree. GUIMIGRATOR generates the final UI code files utilizing target code templates, which are then compiled and validated in the iOS development platform, i.e., Xcode. We evaluate the effectiveness of GUIMIGRATOR on 31 Android open source applications across ten domains. The results show that GUIMIGRATOR achieves a UI similarity score of 78 between migration screenshots, outperforming two popular existing LLMs substantially. Additionally, GUIMIGRATOR demonstrates high efficiency, taking only 7.6 seconds to migrate the datasets. These findings indicate that GUIMIGRATOR effectively facilitates the reuse of Android UI code on iOS, leveraging the strengths of both platforms UI frameworks and making new contributions to cross platform development.

Introduction

User interface (UI) development is often the most expensive component of mobile application engineering, accounting for over 50% of total development costs. While developers strive for cross-platform consistency, the underlying frameworks—Android's imperative XML layouts and iOS's declarative SwiftUI—are fundamentally different. Existing automation attempts, such as computer vision (CV) "screenshot-to-code" tools, often suffer from recognition errors that lead to broken layouts. Similarly, Large Language Models (LLMs) frequently "hallucinate" non-existent UI properties or restructure code in ways that deviate from the original design.

To bridge this gap, we introduce GUIMIGRATOR, a rule-based tool that provides a reliable source-to-source migration path. By parsing source XML and resource files directly, GUIMIGRATOR preserves the original UI structure without the pitfalls of image recognition.

Overview of the GUIMIGRATOR migration process from Android XML to SwiftUI.

Methodology

GUIMIGRATOR follows a structured three-step pipeline to ensure high fidelity and efficiency:

1. Android UI Parsing

Instead of analyzing pixels, the tool parses the Android res directory. It extracts layouts, views, and resources (colors, strings, dimensions) to construct a UI skeleton tree. A "Global Resource Search" mechanism handles nested references to ensure that final values, such as hex colors and text sizes, are accurately captured.

Step 1 of the pipeline: Parsing Android UI layouts and resources into a skeleton tree.

2. UI Translation

The core engine employs specific "Translators" for different layout types. Simple containers like LinearLayout are mapped to SwiftUI’s HStack or VStack. For complex layouts like ConstraintLayout, which lacks a 1:1 equivalent in SwiftUI, the tool utilizes a simulation strategy, nesting ZStack, VStack, and HStack to replicate relative positioning.

3. iOS UI Generation

The translated model is fed into code templates to produce valid SwiftUI files. The tool includes a "Compilation Check" to identify syntax errors before the code is exported to Xcode, ensuring a smoother developer experience.

Experimental Results

We evaluated GUIMIGRATOR using a dataset of 31 open-source Android applications spanning ten domains, including 500 XML files and over 2,500 individual views. The performance was benchmarked against ChatGPT (GPT-3.5) and Command R+.

  • Visual Fidelity: GUIMIGRATOR achieved a 78.17% Structural Similarity Index (SSIM) score, significantly outperforming ChatGPT (64.46%) and Command R+ (66.45%).
  • Efficiency: The entire dataset of 500 files was migrated in just 7.6 seconds, making it 53x to 68x faster than LLM-based approaches.
  • Migration Success: The tool successfully migrated 90.6% of XML files and 94.45% of layouts, requiring a minimal "Code Relative Change" (CRC) of only 2.85% for manual production-ready tweaks.

Discussion and Conclusion

GUIMIGRATOR demonstrates that a code-to-code approach is superior to image-to-code for maintaining UI consistency. By using underlying XML as the ground truth, it ensures that UI elements retain their exact properties across platforms. While currently focused on official Android frameworks and visual layouts, future work will explore third-party library support and the migration of dynamic business logic. Overall, GUIMIGRATOR provides an efficient, high-fidelity solution for cross-platform UI reuse.

Summary updated

Abstract

In the mobile development process, creating the user interface (UI) is highly resource intensive. Consequently, numerous studies have focused on automating UI development, such as generating UI from screenshots or design specifications. However, they heavily rely on computer vision techniques for image recognition. Any recognition errors can cause invalid UI element generation, compromising the effectiveness of these automated approaches. Moreover, developing an app UI from scratch remains a time consuming and labor intensive task. To address this challenge, we propose a novel approach called GUIMIGRATOR, which enables the cross platform migration of existing Android app UIs to iOS, thereby automatically generating UI to facilitate the reuse of existing UI. This approach not only avoids errors from screenshot recognition but also reduces the cost of developing UIs from scratch. GUIMIGRATOR extracts and parses Android UI layouts, views, and resources to construct a UI skeleton tree. GUIMIGRATOR generates the final UI code files utilizing target code templates, which are then compiled and validated in the iOS development platform, i.e., Xcode. We evaluate the effectiveness of GUIMIGRATOR on 31 Android open source applications across ten domains. The results show that GUIMIGRATOR achieves a UI similarity score of 78 between migration screenshots, outperforming two popular existing LLMs substantially. Additionally, GUIMIGRATOR demonstrates high efficiency, taking only 7.6 seconds to migrate the datasets. These findings indicate that GUIMIGRATOR effectively facilitates the reuse of Android UI code on iOS, leveraging the strengths of both platforms UI frameworks and making new contributions to cross platform development.
BibTeX
@misc{gao2024rule,
  author = {Yi Gao and Xing Hu and Tongtong Xu and Xin Xia and Xiaohu Yang},
  title = {{A Rule-Based Approach for UI Migration from Android to iOS}},
  year = {2024},
  eprint = {2409.16656},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2409.16656},
}

Loading related content...

Figure