Generated banner for Migrate Xml Views To Jetpack Compose
Generated logo for Migrate Xml Views To Jetpack Compose

Migrate Xml Views To Jetpack Compose

Android (Google)OfficialCreated by Google LLCDistributed by Android (Google)

  • Skill
  • Workflow
  • Software development
  • Apache-2.0
  • No issues found

From the author

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.
— the description by Google LLC

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a systematic methodology for converting Android XML Views into declarative Jetpack Compose components. It emphasizes maintaining visual parity and functional integrity through a rigorous process that includes project analysis, dependency setup, theming alignment, and validation. The workflow is designed for incremental adoption, ensuring that legacy XML and new Compose code can coexist through interoperability APIs while preparing the codebase for a full transition to Compose.

What it does

  • Analyzes existing XML layouts and project infrastructure for migration readiness.
  • Guides the setup of Compose dependencies and compiler configurations.
  • Facilitates the migration of XML themes to Material 3 Compose theming.
  • Provides a structured approach to replacing XML View usages with Compose components.
  • Ensures visual parity through automated screenshot testing and Compose Previews.
  • Manages the safe removal of legacy XML files and associated resources.

When to use it

  • When modernizing an Android application's UI layer from XML to Jetpack Compose.
  • When you need to perform an incremental migration of specific UI components.
  • When you need to ensure visual consistency between legacy XML and new Compose code.
  • When integrating new Compose features into an existing View-based Android project.

Advantages

  • Reduces risk by following a validated, step-by-step migration methodology.
  • Maintains project stability through interoperability best practices.
  • Ensures visual fidelity using baseline screenshot comparisons.
  • Promotes clean code by systematically removing redundant legacy XML resources.

Usage examples

“Help me migrate my login_screen.xml to Jetpack Compose.”
The agent will initiate the 10-step workflow, starting with an analysis of the login_screen.xml structure and project dependencies to create a migration plan.
“How do I handle theming when moving from XML to Compose?”
The agent will guide you through mapping XML color attributes and styles to Material 3 semantic roles within a Compose MaterialTheme.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/android/migrate-xml-views-to-jetpack-compose/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip migrate-xml-views-to-jetpack-compose.zip -d .agents/skills

Documentation by Google LLC

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 removal

Delete the migrated XML file and its associated legacy tests. Caution: Only remove code and resources that are not referenced by other parts of the project.

Files

references/android/develop/ui/compose/designsystems/migrate-xml-theme-to-compose.md

When you introduce Compose in an existing app, you need to migrate your Material XML themes to use MaterialTheme for Compose components. This means your app's theming will have two sources of truth: the View-based theme and the Compose theme. Any changes to your styling need to be made in multiple places. Once your app is fully migrated to Compose, remove your XML theming.

You can use the Material Theme Builder tool for migrating colors.

When you start the migration from XML to Compose, migrate the theming to Material 3 Compose theming.

Glossary

TermDefinition
MaterialThemeThe composable function that provides theming (colors, typography, shapes) to Compose UI components.
ShapesA Compose object used to define custom component shapes for a MaterialTheme.
TypographyA Compose object used to define custom text styles (font families, sizes, weights) for a MaterialTheme.
ColorSchemeA Compose object used to define custom color schemes for MaterialTheme.
XML ThemeThe Android theming system defined in XML files, used by the View system.

Limitations

Before migrating, be aware of the following limitations:

  • This guide focuses on migrating to Material 3 only. For migrating from alternative design systems, see Material 2 or Custom design systems in Compose.

  • The ultimate goal is a complete migration to Compose, which allows for the removal of XML theming. This guide explains how to migrate, but it doesn't explain how to finally remove XML theming.

Step 1: Evaluate the design system

Identify which design system is used in the XML View project. Analyze the migration path and necessary steps to migrate the existing design system to Material 3 in Compose.

Step 2: Identify theme source files

In XML you write ?attr/colorPrimary. In Compose, you access theme values with MaterialTheme.*:

Identify and locate all XML resources and files necessary for theming: light and dark color schemes and qualifiers, themes, shapes, dimensions, typography, styles and other relevant files.

Resources such as strings can be reused as is and don't need to be migrated.

Step 3: Migrate colors

Key principle: XML uses named hex colors. Material 3 uses semantic roles (e.g., primary, onPrimary, surface). Stop naming colors by their hex; name them by their role.

Examples:

XML color nameMaterial 3 role
colorPrimaryprimary
colorPrimaryDark / colorPrimaryVariantprimaryContainer or secondary
colorAccentsecondary or tertiary
colorOnPrimaryonPrimary
android:colorBackgroundbackground
colorSurfacesurface
colorOnSurfaceonSurface
colorErrorerror
colorOnErroronError
colorOutlineoutline
colorSurfaceVariantsurfaceVariant
colorOnSurfaceVariantonSurfaceVariant

Migrate the dark and light color schemes from XML to their equivalents in Material 3 Compose.

[!NOTE] Note: Material 3 naming differs from Material 2 color naming.

Step 4: Migrate custom shapes and typography

  • If your app uses custom shapes:

    1. In your Compose code, define a Shapes object to replicate your XML shape definitions.

    2. Provide this Shapes object to your MaterialTheme.

      For more details, see shapes.

  • If your app uses custom typography:

    1. In your Compose code, define a Typography object in your Compose code to replicate your XML text styles and font definitions.

    2. Provide this Typography object to your MaterialTheme.

      For more details, see typography.

Compose roleXML name
displayLargeTextAppearance.Material3.DisplayLarge
displayMediumTextAppearance.Material3.DisplayMedium
displaySmallTextAppearance.Material3.DisplaySmall
headlineLargeTextAppearance.Material3.HeadlineLarge
headlineMediumTextAppearance.Material3.HeadlineMedium
headlineSmallTextAppearance.Material3.HeadlineSmall
titleLargeTextAppearance.Material3.TitleLarge
titleMediumTextAppearance.Material3.TitleMedium
titleSmallTextAppearance.Material3.TitleSmall
bodyLargeTextAppearance.Material3.BodyLarge
bodyMediumTextAppearance.Material3.BodyMedium
bodySmallTextAppearance.Material3.BodySmall
labelLargeTextAppearance.Material3.LabelLarge
labelMediumTextAppearance.Material3.LabelMedium
labelSmallTextAppearance.Material3.LabelSmall

Step 5: Migrate styles (styles.xml)

XML styles (styles.xml) system defines styles and appearance of:

  1. Widgets, components, themes for windows and dialogs

  2. Typography

  3. Themes and overlays

  4. Shapes

XML Views and components combine multiple attributes to create a style. They set their styles from styles.xml in two different ways:

  1. Setting "style="@style/..." directly and explicitly in the XML View

  2. Setting the style indirectly and implicitly for a component as part of a larger Theme (theme.xml)

Styles have no direct equivalent in Compose - instead styles are passed as: parameters or modifiers to composables, using the new, experimental Styles API defined in the AppTheme, or by creating layered, reusable composable variations with the defined style.

Provide separate @Composable functions named according to the style and the base component, to signify the difference in styling and use cases for those components.

  • Pattern: If an XML element uses a custom style (e.g., style="@style/MyPrimaryButton"), don't try to replicate the style inline. Instead, suggest creating a specific composable.

  • Example:

    • XML: <Button style="@style/MyPrimaryButton" ... />

    • Compose: MyPrimaryButton(onClick = { ... })

  • Common Attribute Groups: If a style sets common modifiers (like padding + height), extract them into a readable extension property or a shared Modifier variable.

Common examples
XMLCompose
Theme.Material3.*MaterialTheme(colorScheme, typography, shapes) { }
TextAppearance.Material3.BodyMediumTextStyle(...) defined in Typography(bodyMedium = ...)
ShapeAppearance.*.SmallComponentShapes(small = RoundedCornerShape(X.dp))
Widget.Material3.ButtonButton(colors = ButtonDefaults.buttonColors(...))
Widget.Material3.CardViewCard(shape=..., elevation=..., colors=...)
Widget.*.TextInputLayout.OutlinedBoxOutlinedTextField(colors = OutlinedTextFieldDefaults.colors(...))
Widget.*.Chip.FilterFilterChip(colors = FilterChipDefaults.filterChipColors(...))
Widget.*.Toolbar.PrimaryTopAppBar(colors = TopAppBarDefaults.topAppBarColors(...))
Widget.*.FloatingActionButtonFloatingActionButton(containerColor = ...)
backgroundTintcontainerColor in ComponentDefaults.ComponentColors()
android:textColorcontentColor in ComponentDefaults.ComponentColors()
cornerRadiusshape = RoundedCornerShape(X.dp)
android:elevationelevation = ComponentDefaults.elevation(defaultElevation = X.dp)
android:paddingcontentPadding = PaddingValues(...) or Modifier.padding()
android:minHeightModifier.heightIn(min = X.dp)
strokeColor + strokeWidthborder = BorderStroke(width, color)
android:textSizefontSize = X.sp in TextStyle

Step 6: Validate the theme migration

Always use the existing theme values from the original XML theme as the source of truth for the new Material Theme in Compose. Never invent new theme values during migration, to maintain brand consistency and avoid visual regressions.

Verify all new Compose theme values match the existing XML values. Don't hardcode any migrated values.

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
Google LLC
Publisher
Android (Google) (Official)
Distributed by
Android (Google)
Source
android/skills · jetpack-compose/migration/migrate-xml-views-to-jetpack-compose · commit bf68e2d
Licence
Apache License 2.0 (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE.txt)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Google LLC or Android (Google).

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download migrate-xml-views-to-jetpack-compose.zip