Skip to content

[BREAKING] fix!: Include original file extension in retargeted drawables on Android - #15891

Merged
MartinZikmund merged 6 commits into
masterfrom
dev/mazi/android-svg
Oct 7, 2026
Merged

MartinZikmund merged 6 commits into
masterfrom
dev/mazi/android-svg

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Mar 16, 2024 •

Copy link
Copy Markdown
Member

GitHub Issue (If applicable): closes #9618

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Other... Please describe: contains a breaking change to Android drawable resource names

What is the current behavior?

When retargeting assets for Android, AndroidResourceNameEncoder drops the file extension when building the drawable name. Assets/logo.png becomes the drawable Assets_logo.png (resource name Assets_logo), and the extension is not part of the name.

That has two consequences:

  1. Assets that only differ by their extension collide. Assets/logo.png and Assets/logo.jpg both map to the drawable Assets_logo, so only one of them is usable ([Android] Assets with the same name and different extension don't work properly [7.0] #9618).
  2. Assets that are not retargeted to drawables are shadowed by ones that are. .svg is not a drawable format, so Assets/logo.svg stays a plain Android asset - but StorageFile.GetFileFromApplicationUriAsync looks for a drawable first, resolves Assets_logo, and hands back the PNG instead of the SVG.

What is the new behavior?

The original extension is folded into the drawable's resource name:

Logical path Before After
Assets/logo.png Assets_logo.png Assets_logo_png.png
Assets/logo.jpg Assets_logo.jpg Assets_logo_jpg.jpg
Assets/logo.9.png Assets_logo.9.png Assets_logo_png.9.png

Both files now get their own drawable, and a non-drawable asset can no longer be shadowed by a drawable that happens to share its base name.

AndroidResourceNameEncoder gains EncodeDrawableResourceName, which returns the R.drawable field name for a given asset path. Android derives that name from the file name up to its first dot, so it is not simply the encoded file name minus its extension - nine-patch drawables keep a .9 in the file name that is absent from the resource name. DrawableHelper now uses that method for lookups rather than re-deriving the name with string operations, and a test asserts the two stay in sync.

Encode, EncodeResourcePath and EncodeFileSystemPath are unchanged: assets that are not drawables keep their existing names and layout.

Breaking change

Every retargeted Android drawable is renamed. Apps are affected if they:

  • reference a retargeted asset by its generated resource id, e.g. Resource.Drawable.Assets_logo becomes Resource.Drawable.Assets_logo_png;
  • call DrawableHelper.FindResourceId with a name that has no extension - FindResourceId("logo") no longer resolves, FindResourceId("logo.png") does;
  • load a drawable they authored under Platforms/Android/Resources/drawable through an ms-appx:/// URI. ms-appx:///foo.png now looks for foo_png, so an authored foo no longer resolves this way and no longer counts as existing for StorageFileHelper.ExistsInPackage. This is intentional: falling back to the extensionless name would bring back the same-stem shadowing this PR removes. Load such images from Assets instead, or reference the native drawable directly. Native references such as Resource.Drawable.foo and Android XML are unaffected.

XAML and code that load Uno-packaged assets by ms-appx:/// URI or relative path are unaffected. Both breaks are documented in the 7.0 migration guide (Behavioral changes).

PR Checklist

Please check if your PR fulfills the following requirements:

This PR contains a breaking change, described above. #9618 is tagged for 7.0, which is the target for this change.

Other information

AndroidResourceNameEncoder.cs was converted to a file-scoped namespace, which reindents the whole file. Reviewing with whitespace changes hidden keeps the diff to the handful of lines that actually changed.

@github-actions github-actions Bot added the platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform label Mar 16, 2024
@MartinZikmund
MartinZikmund marked this pull request as ready for review March 16, 2024 05:08
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Mar 16, 2024
@MartinZikmund MartinZikmund self-assigned this Mar 16, 2024
@unodevops

Copy link
Copy Markdown
Contributor

@jeromelaban

Copy link
Copy Markdown
Member

This is a breaking change for apps that use this type of assets natively on android. why is it required?

@MartinZikmund

Copy link
Copy Markdown
Member Author

This is a breaking change for apps that use this type of assets natively on android. why is it required?

It follows up investigation of #15866, but I have hit it before as well. The issue is that while on all targets the extension of the image is significant, on Android the extension is ignored and only one of the files is ultimately usable. I guess it is an edge case, but we should either do this or at least warn the user or show an error, when we are retargeting two assets with the same name on Android

@jeromelaban

jeromelaban commented Mar 25, 2024 •

Copy link
Copy Markdown
Member

@MartinZikmund I see. The origin of the issue is caused by duplicate files, which should not happen in the first place as I understand. We may make this change in our next major, but it's a very subtle break that is not easy to spot.

@MartinZikmund MartinZikmund changed the title fix: Include original file extension in retargeted drawables on Android [BREAKING] fix!: Include original file extension in retargeted drawables on Android Mar 25, 2024
@MartinZikmund
MartinZikmund marked this pull request as draft March 25, 2024 13:36
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days.

@github-actions github-actions Bot added the stale This item has been marked as stale and will be closed if there is no activity. label Jan 31, 2025
@MartinZikmund MartinZikmund removed the stale This item has been marked as stale and will be closed if there is no activity. label Feb 1, 2025
@github-actions

github-actions Bot commented Apr 5, 2025

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days.

@github-actions github-actions Bot added the stale This item has been marked as stale and will be closed if there is no activity. label Apr 5, 2025
@MartinZikmund MartinZikmund removed the stale This item has been marked as stale and will be closed if there is no activity. label Apr 6, 2025
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/android-svg branch from 2184f98 to 7f555ef Compare June 11, 2025 14:05
@unodevops

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days.

@github-actions github-actions Bot added the stale This item has been marked as stale and will be closed if there is no activity. label Aug 11, 2025
@MartinZikmund MartinZikmund removed the stale This item has been marked as stale and will be closed if there is no activity. label Aug 11, 2025
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days.

@github-actions github-actions Bot added the stale This item has been marked as stale and will be closed if there is no activity. label Oct 11, 2025
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 10 days with no activity.

@github-actions github-actions Bot closed this Oct 21, 2025
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 5, 2026
@MartinZikmund MartinZikmund removed the stale This item has been marked as stale and will be closed if there is no activity. label Jul 2, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Oct 5, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Oct 5, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Oct 5, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 5, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 5, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 5, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 5, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 5, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 5, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 5, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 5, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 5, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 237402 found UI Test snapshots differences: skia-linux-screenshots: 113, skia-windows-screenshots: 213

Details
  • skia-linux-screenshots: 113 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • ClipboardTests.png-dark
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • CalendarView_Theming.png-dark
    • Buttons.png
    • CalendarView_Theming.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Focus_FocusVisual_Properties.png-dark
  • skia-windows-screenshots: 213 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • DisplayInformation.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Examples.png
    • Grid_Multi_Column_Span.png-dark
    • Grid_Multi_Column_Span.png
    • Grid_RowSpan_Auto_WithText.png-dark
    • Grid_RowSpan_Auto_WithText.png
    • Grid_RowSpan_Right.png-dark
    • Grid_RowSpan_Right.png
    • Grid_ScrollViewer.png-dark
    • Grid_ScrollViewer.png
    • Image_UseTargetSizeLate.png-dark

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 1m 24s —— View job


Re-review on pull_request synchronize

  • Gather context (prior review rounds, current HEAD, new commits since last review)
  • Review the new doc/articles/migrating-to-uno-7.md addition
  • Re-check the unresolved Copilot findings (authored-drawable lookup regression) against MartinZikmund's responses
  • Review remaining changed files against AGENTS.md guidelines
  • Post inline comments for any new/unresolved findings (none)
  • Post summary verdict

Summary

Verdict: ship. No inline comments. Since the last full review round (which covered commits through 10bbc79c), exactly one new commit landed: 28ef6ec7 ("docs(android): Note the retargeted drawable rename for 7.0"), a 13-line, docs-only addition to doc/articles/migrating-to-uno-7.md. No source files changed.

  • The new doc section accurately mirrors the PR description's breaking-change summary: retargeted drawables gain the extension in their resource name (Resource.Drawable.Assets_logo → Resource.Drawable.Assets_logo_png), and drawables authored under Platforms/Android/Resources/drawable no longer resolve via ms-appx:/// by their bare name. This closes the "breaking-change doc note" gap every prior review round flagged as outstanding.
  • Checked it against the repo's Public Documentation rules (AGENTS.md): no private issue/PR/repo references, phrased generically — compliant.
  • Re-verified AndroidResourceNameEncoder.cs, DrawableHelper.Android.cs, and StorageFileHelper.Android.cs are byte-identical to the versions reviewed in the last round — confirms no regressions were reintroduced alongside the doc commit.

On the newest Copilot comment (2026-10-05T10:40:31Z) flagging DrawableHelper.Android.cs:88 and StorageFileHelper.Android.cs:36 as "critical" regressions for authored drawables: this is not a new or unaddressed defect. It's the second, intentional half of this PR's documented breaking change — ms-appx:///foo.png now resolves to the drawable foo_png rather than foo, which the PR description calls out explicitly ("intentional: falling back to the extensionless name would bring back the same-stem shadowing this PR removes") and which 28ef6ec7 now also documents in the migration guide. Both files encode via the same EncodeDrawableResourceName used for packaging, so lookup and packaging stay in sync — there's no drift, just the accepted behavior change.

Cross-cutting notes (non-blocking, already surfaced in-thread):

  • All CI checks for this push (Copilot review, CodeQL, Code Quality, link check) were still in progress at the time of this review — no new failures to report.
  • PR checklist box for screenshot-compare validation is still unchecked; worth a final maintainer confirmation given the broad, untargeted screenshot-diff noise observed on earlier pushes (unrelated controls — buttons, calendar, media player — not touched by this PR).

Validation: Code review by direct inspection of the current file contents (not diff-only, since this is a shallow checkout without origin/master history available in this sandbox) plus git show of the new commit. No dotnet test/dotnet build run in this sandbox (network/build execution requires interactive approval not available here); no source changed since the last round's trace-verified pass, so no new runtime risk introduced.
(branch: dev/mazi/android-svg)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Address the documented FindResourceId guidance and mipmap lookup compatibility concern.

Review effort: Lite
Findings: 1 Low severity

Open (1)
Resolved since last review (2)

Comment thread doc/articles/migrating-to-uno-7.md Resolved
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 237456 found UI Test snapshots differences: skia-windows-screenshots: 148, skia-linux-screenshots: 120

Details
  • skia-windows-screenshots: 148 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • CalendarView_Theming.png-dark
    • ClipboardTests.png-dark
    • DisplayInformation.png-dark
    • Examples.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • ImageIconPage.png-dark
    • Grid_with_Fixed_Size.png-dark
    • Grid_with_Fixed_Size.png
    • Image_UseTargetSizeLate.png-dark
    • Image_UseTargetSizeLate.png
  • skia-linux-screenshots: 120 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • ClipboardTests.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DisplayInformation.png-dark
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • ImageIconPage.png
    • DropDownButtonPage.png-dark
    • Examples.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • ElementLevelTheme.png-dark

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 237456 has failed on Uno.UI - CI.

Updated drawable resource handling to include file extensions, affecting how resources are referenced in code.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 16s —— View job


Re-review on pull_request synchronize

Verdict: ship. I have no inline comments.

Since the last round, one commit landed: bb3fa004. It changes only doc/articles/migrating-to-uno-7.md, and no source files changed.

  • What it fixes: The commit closes the one open Copilot thread, the missing DrawableHelper.FindResourceId note. The migration guide now says callers must pass the file name with its extension. FindResourceId("logo.png") resolves and FindResourceId("logo") no longer does. This matches the "Breaking change" section of the PR description.
  • Public-docs rule: The new text has no private issue, PR or repo references, so it follows the public-documentation rule in AGENTS.md.
  • Style nit (non-blocking): The edited bullet has uneven line wrapping. The new lines are longer than the surrounding ~100-column wrap. This is cosmetic.

Other notes (non-blocking):

  • The PR description's "Contains NO breaking changes" box is correctly left unchecked.
  • The screenshot-compare box is still unchecked. The diffs on earlier pushes were broad (buttons, calendar, clipboard and similar controls) and unrelated to Android drawable naming, so they look like baseline noise. A maintainer should confirm that before merge.
  • The ms-appx query-string gap is deferred to ms-appx URIs with a query string or fragment don't resolve #24448.

Validation: Code review only, from the commit diff. I did not build or run tests, and no source changed in this push.
· branch dev/mazi/android-svg

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 237921 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 1138

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • Buttons.png-dark
    • Buttons.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DisplayInformation.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • DropDownButtonPage.png-dark
    • Focus_FocusVisual_Properties.png-dark
  • skia-windows-screenshots: 1138 changed over 2474

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • BorderVersusPanelClipping.png-dark
    • BorderVersusPanelClipping.png
    • Border_Simple.png-dark
    • Border_Simple.png
    • Button_Opacity_Automated.png-dark
    • Button_Opacity_Automated.png
    • CenteredGridinGridwithtwofixedsizechildren.png-dark
    • CenteredGridinGridwithtwofixedsizechildren.png
    • ChatBox.png-dark
    • ChatBox.png
    • ColorAnimationUsingKeyFrames_Fill.png-dark
    • ColorAnimationUsingKeyFrames_Fill.png
    • ComboBox_Stretch.png-dark
    • ComboBox_Stretch.png
    • ContentControl_ComboBoxSetNull.png-dark
    • ContentControl_ComboBoxSetNull.png
    • ContentPresenter_NativeEmbedding_ZIndex.png-dark

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 237921 has failed on Uno.UI - CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation kind/documentation platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Assets with the same name and different extension don't work properly [7.0]

7 participants