Problem building for Android: Resources\values\colors.xml : error APT2126

HH 5 Reputation points
2025-05-27T09:53:57.24+00:00

Hi, I've made a MAUI app using VS Code that works on Windows and now I want to run it in an.....

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Tony Dinh (WICLOUD CORPORATION) 725 Reputation points Microsoft External Staff
    2025-08-12T04:16:39.12+00:00

    Hi HH!

    The error APT2126 indicates a problem with AAPT (Android Asset Packaging Tool) when processing your XML resource files in your MAUI project, especially in colors.xml. Here are some possible causes for this issue:

    • Invalid XML syntax in colors.xml: Check for missing closing tags, incorrect nesting, or unescaped characters
    • Unsupported color format: The file might be using color values that Android doesn't recognize
    • Duplicate resource names: You may have two color entries with the same name
    • Invalid resource references: Check for broken references to other resources

    Here's some solution you can try:

    1. Validate your colors.xml file:

    Open Platforms/Android/Resources/values/colors.xml and ensure:

    • Proper XML structure with <resources> root element and XML declaration
    • Valid color values (hex formats: #RGB, #ARGB, #RRGGBB, #AARRGGBB)
    • Unique names for each color entry
    • No special characters or spaces in color names
    • No Android reserved keywords

    Example of correct format:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="primary">#6200EE</color>
        <color name="primary_dark">#3700B3</color>
        <color name="accent">#03DAC6</color>
    </resources>
    

    2. Clean and Rebuild:

    For MAUI projects in VS Code, use these commands:

    dotnet clean
    dotnet build
    

    3. Check for Common Issues:

    • Missing XML declaration: Add <?xml version="1.0" encoding="utf-8"?> at the top
    • Unclosed tags: Every <color> must have </color>
    • Invalid characters: Remove any non-standard quotes or invisible characters

    4. Last Resort - Recreate File:

    If the file appears corrupted:

    • Delete colors.xml
    • Run dotnet clean
    • Recreate with minimal content and test

    I hope this help, if the problem persists, please share:

    • The exact content of your colors.xml file
    • Your project's target framework (e.g., net8.0-android)
    • The complete error stack trace
    • Your MAUI workload version (dotnet workload list)

    This will help me provide more specific assistance!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.