Index of every page on this site: llms.txt
All skills
android avatar

/migrate-xml-views-to-jetpack-compose

@7f7b217
by androidandroid/skills11k stars
703
Run it yourself

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.

Use this Skill: https://skilld.dev/gh/android/skills/migrate-xml-views-to-jetpack-compose

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesxml-layout-migration.md

≈891 tokens on demand. Your agent reads this file only when SKILL.md points to it.

1. Structural analysis & mapping

Identify the precise mapping between XML elements and Compose equivalents. You must determine:

  • The exact @Composable functions (e.g., ConstraintLayout, Column, LazyColumn) that replace the XML tag hierarchy.
  • The specific parameters and Modifier extensions required to replicate XML attributes (e.g., layout_width, padding, elevation).
  • The appropriate state management strategy for interactive elements.

2. Migration execution

Convert the XML layout code to Jetpack Compose, ensuring the visual hierarchy and layout logic are preserved while leveraging Compose's declarative nature.

3. Theming & design system integrity

Do not use hard-coded values. Follow these rules for styling:

  • Token Alignment: Cross-reference XML dimensions, colors, and style attributes with the existing Compose Theme (e.g., MaterialTheme.colorScheme or custom design system tokens).
  • Reuse over Creation: If matching values exist in the current Compose theme, reuse them. If a value is missing but required for the design, define it within the theme structure rather than hard-coding it in the Composable.
  • Project Consistency: You MUST strictly adhere to existing code conventions, naming standards, and implementation patterns found in the project. Prioritize project-specific reusable components over generic Material defaults.

4. Component layering & reusability

Evaluate if the XML layout serves as a foundation-level design system component (reused across the app with a distinct role). If it is:

  • Create a reusable composable: Do not just inline the code. Define a new standalone @Composable.
  • Parameterization: Expose specific parameters for variable data (text, colors, styles) and use Modifier for layout-specific customizations.
  • Feature parity & restriction: Ensure the new composable enforces the same UI constraints as the original XML component, preventing unauthorized style overrides while maintaining the intended flexibility.

Example before migration:

<style
    name="Widget.Rounded.Button"
    parent="Widget.Button.Borderless">
    <item name="android:fontFamily">sans-serif-medium</item>
    <item name="android:minWidth">@dimen/min_width</item>
    <item name="android:paddingStart">@dimen/padding_2</item>
    <item name="android:paddingEnd">@dimen/padding_2</item>
    <item name="cornerRadius">8dp</item>
</style>

Example after migration:

@Composable
fun RoundedBorderlessButton(
    text: String,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true
) {
    TextButton(
        onClick, modifier
            .defaultMinSize(minWidth = dimensionResource(R.dimen.min_width))
            .padding(
                start = dimensionResource(R.dimen.padding_2),
                end = dimensionResource(R.dimen.padding_2)
            ), enabled, shape = RoundedCornerShape(8.dp),
        colors = ButtonDefaults.textButtonColors(
            contentColor = MaterialTheme.colorScheme.primary
        )
    ) {
        Text(
            text = text,
            style = MaterialTheme.typography.bodyMedium.copy(
                fontFamily = FontFamily.SansSerif,
                fontWeight = FontWeight.Medium
            )
        )
    }
}
<br />

5. Output requirements

  • Provide the full Kotlin file content.
  • Include necessary imports.
  • Add documentation comments (/** ... */) explaining the mapping logic for complex transformations.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts7d4 checks · Risk SAFE
  • Gen Agent Trust Hub7d

    The skill provides a legitimate technical workflow for migrating Android XML layouts to Jetpack Compose using official Google dependencies and standard Android development tools. No malicious behavior was detected.

  • Socket7d

    No alerts

  • Snyk7d

    Risk: LOW · No issues

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 7f7b217. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 30 minutes ago.

Activeupdated last week
Other metadata
metadata
{
  "author": "Google LLC",
  "last-updated": "2026-11-12",
  "keywords": [
    "Jetpack Compose",
    "migration",
    "XML",
    "Views",
    "interoperability",
    "incremental adoption",
    "UI development"
  ]
}

README badge

README badge for android/skills/migrate-xml-views-to-jetpack-compose