跳到正文
Skillpedia
移动应用10k · #11922

migrate-xml-views-to-jetpack-compose

它能做什么

这个技能指导把 Android 应用中单个旧版 XML 布局转换为 Jetpack Compose。它会保持外观一致,并在移除旧 XML 之前检查结果。适合更新旧界面的 Android 开发者。

适用场景

  • ✓当你有一个使用 XML 视图构建的旧 Android 界面,并希望把它迁移到 Jetpack Compose 时。
  • ✓当你想选出最适合先迁移的 XML 布局的时候。
  • ✓当你需要一份计划和视觉检查,使新的 Compose 界面与旧界面一致的时候。

技能链接

https://github.com/android/skills/blob/main/jetpack-compose/migration/migrate-xml-views-to-jetpack-compose/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/android/skills/blob/main/jetpack-compose/migration/migrate-xml-views-to-jetpack-compose/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请把我的设置界面从 XML 视图迁移到 Jetpack Compose,并保持外观不变。”

每周 5 个新技能,1 分钟读完。

工作原理

该技能按十个步骤推进,从选择和分析布局,到设置 Compose 和主题。它会截取旧界面、构建 Compose 版本、进行视觉检查,然后替换旧的用法并删除 XML。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

This skill guides through the process of migrating an existing Android XML View to Jetpack Compose. It performs a stable, safe and visually consistent transition by following a structured, 10-step methodology. This skill migrates UI (XML to Jetpack Compose) only.

Objective

To systematically convert a single legacy XML layout into modern, declarative Jetpack Compose UI while maintaining pixel-perfect visual parity and functional integrity.

Summary of the 10-step migration process

  1. Identify the optimal XML candidate for migration
  2. Analyze the project and layout
  3. Create a plan
  4. Capture the XML View UI
  5. Set up Compose dependencies and compiler
  6. Set up Compose theming
  7. Migrate the XML layout to Compose
  8. Validate the migration
  9. Replace usages
  10. XML code removal

Detailed steps

Step 1: Identify the optimal XML candidate for migration

If the user has explicitly specified a target XML layout, proceed to Step 2. Otherwise, analyze the codebase to identify the best candidate for migration by following the logic in references/identify-optimal-xml-candidate.md.

Step 2: Analyze the project and layout

Analyze the identified XML View's structure, hierarchy, and implementation details. Use references/analysis-of-the-project-and-layout.md to guide your technical audit of the layout and surrounding project context.

Step 3: Create a plan

Using the outputs and analysis done in the Step 1 and 2, generate a step-by-step plan for the migration. If you support user interaction, present to the user and ask for approval before proceeding. If user interaction is not supported, proceed to Step 4 following the generated plan.

Step 4: Capture the XML View UI

IF you support user interaction, ask the user to upload a screenshot of the XML View UI or provide an absolute path to a file. Use this image as a visual reference for the layout migration in Step 7. ELSE IF you are able to run an Android emulator, locate an existing screenshot test for the XML candidate. If none exists, create one using the existing project testing framework. If no framework exists, use UI Automator or Espresso to create a screenshot test with minimum required setup. Run the test and take a baseline screenshot of the XML UI. ELSE proceed to Step 5.

Step 5: Set up Compose dependencies and compiler

Check build.gradle or libs.versions.toml for Compose dependencies and compiler setup. If missing, use Setup Compose Dependencies and Compiler. Run a sync to ensure dependencies resolve without errors.

Step 6: Set up Compose theming

If the project already has Compose theming set up, proceed to Step 7. If Compose theming is missing, initialize it. For Material-based projects, follow Material 3 migration guidelines. For custom design systems, apply expert judgment to migrate XML theming and match existing styles. Constraints: Do not migrate the entire theme. Implement only the minimum theming required for the specific XML candidate. Maintain original XML themes for interoperability. Maintain existing project code conventions, patterns, names and values.

Step 7: Migrate the XML View to Compose

Convert the XML candidate to Jetpack Compose code, referencing references/xml-layout-migration.md and the image from Step 4. You must include a Compose Preview for the newly created composable to facilitate visual verification.

Step 8: Replace usages

Replace the usages of the migrated XML layout to use the new Compose component.

Step 9: Validate the migration

Compare the baseline screenshot image from Step 4 with the rendered Compose Preview of the new composable. Ignore string content; focus on layout and styling. Iterate on the Compose code until visual parity is achieved. Once verified, write a Compose UI test for the new composable.

Step 10: XML code remo

常见问题

它会一次性迁移整个应用吗?

不会。它每次迁移一个 XML 布局,你可以选择布局,也可以让该技能来挑选。

它如何检查结果?

它会截取旧界面,并将新的 Compose 界面与之比较,以确认视觉一致性。

它会改变应用的逻辑吗?

不会。该技能只迁移用户界面。

详情

作者的原始描述

Provides a structured workflow for migrating an Android XML View to Jetpack Compose. This skill details the step-by-step process, from planning and dependency setup, to theming and layout migration, validation and XML cleanup. Use this skill when you need to migrate an XML View to Jetpack Compose in an Android project. It solves the problem of converting the UI of a legacy XML View into modern, declarative Compose components while maintaining interoperability.

repo: android/skills

热度

GitHub 星标
10k
排名
#11922
许可证
Apache-2.0
更新时间
2026/10/29

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能