Repository navigation
[BREAKING] fix!: Include original file extension in retargeted drawables on Android - #15891
Conversation
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-15891/index.html |
|
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 |
|
@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. |
|
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. |
|
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. |
2184f98 to
7f555ef
Compare
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-15891/docs/index.html |
|
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. |
|
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. |
|
This PR was closed because it has been stalled for 10 days with no activity. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical lookup regressions affect manually authored Android drawables.
Review effort: Lite
Findings: 2
Open (2)
Resolved since last review (4)
Nine-patch base-name extraction usesNinePatchExtension.Length(\".9.png\") even though… Drawable lookup keys should be normalized the same way Android packages them: resource entry names… Drawable lookup keys should be normalized the same way Android packages them: resource entry names…AlignPathonly normalizes/to the platform separator. On Android the separator is already/,…
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-15891/wasm-skia-net9/index.html |
|
The build 237402 found UI Test snapshots differences: Details
|
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CKYPsdeNEWd1CARAojRx7H
|
Claude finished @MartinZikmund's task in 1m 24s —— View job Re-review on
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-15891/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-15891/docs/index.html |
|
The build 237456 found UI Test snapshots differences: Details
|
|
|
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]>
|
Claude finished @MartinZikmund's task in 16s —— View job Re-review on
|
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-15891/docs/index.html |
|
The build 237921 found UI Test snapshots differences: Details
|
|
|



GitHub Issue (If applicable): closes #9618
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When retargeting assets for Android,
AndroidResourceNameEncoderdrops the file extension when building the drawable name.Assets/logo.pngbecomes the drawableAssets_logo.png(resource nameAssets_logo), and the extension is not part of the name.That has two consequences:
Assets/logo.pngandAssets/logo.jpgboth map to the drawableAssets_logo, so only one of them is usable ([Android] Assets with the same name and different extension don't work properly [7.0] #9618)..svgis not a drawable format, soAssets/logo.svgstays a plain Android asset - butStorageFile.GetFileFromApplicationUriAsynclooks for a drawable first, resolvesAssets_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:
Assets/logo.pngAssets_logo.pngAssets_logo_png.pngAssets/logo.jpgAssets_logo.jpgAssets_logo_jpg.jpgAssets/logo.9.pngAssets_logo.9.pngAssets_logo_png.9.pngBoth 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.
AndroidResourceNameEncodergainsEncodeDrawableResourceName, which returns theR.drawablefield 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.9in the file name that is absent from the resource name.DrawableHelpernow uses that method for lookups rather than re-deriving the name with string operations, and a test asserts the two stay in sync.Encode,EncodeResourcePathandEncodeFileSystemPathare 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:
Resource.Drawable.Assets_logobecomesResource.Drawable.Assets_logo_png;DrawableHelper.FindResourceIdwith a name that has no extension -FindResourceId("logo")no longer resolves,FindResourceId("logo.png")does;Platforms/Android/Resources/drawablethrough anms-appx:///URI.ms-appx:///foo.pngnow looks forfoo_png, so an authoredfoono longer resolves this way and no longer counts as existing forStorageFileHelper.ExistsInPackage. This is intentional: falling back to the extensionless name would bring back the same-stem shadowing this PR removes. Load such images fromAssetsinstead, or reference the native drawable directly. Native references such asResource.Drawable.fooand 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:
Screenshots Compare Test Runresults.This PR contains a breaking change, described above. #9618 is tagged for 7.0, which is the target for this change.
Other information
AndroidResourceNameEncoder.cswas 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.