Skip to content

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

Closed

Description

@MartinZikmund

Current behavior

Suppose the Assets folder in Shared project contains the following:

  • Image.png
  • Image.jpg

Even though both are different actual files, when used in <Image> they are retrieved by DrawableHelper using their "id" which is using GetFileNameWithoutExtension. As a result, only one will display.

Expected behavior

Should allow displaying multiple images with the same name and different extension.

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

Use different image name.

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia, Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

No response

Affected platforms

No response

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

This can be fixed by adjusting the assets retarget task to include the file extension in the file name (e.g. drawables will contain something like Assets_Image_jpg.jpg and Assets_Image_png.png). Then we can use the filename with extension to get the image

Activity

  1. added
    kind/bug
    triage/untriaged
    difficulty/tbd
    platform/android 🤖
    difficulty/starter 🚀
    and removed
    triage/untriaged
    difficulty/tbd
    on Aug 26, 2022
  2. added
    project/core-tools 🛠️
    on Aug 26, 2022
  3. added
    low-hanging-🍒
    difficulty/medium 🤔
    and removed
    difficulty/starter 🚀
    on Aug 14, 2023
  4. github-actions commented on Aug 5, 2025

    @github-actions
    Contributor

    Hey there — just a heads-up that this issue has been quiet for over a year. If there’s no update or comment in the next 10 days, it’ll be closed automatically. Feel free to remove the stale label or drop a note to keep it open.

  5. added
    stale
    on Aug 5, 2025
  6. removed
    stale
    on Aug 5, 2025
  7. MartinZikmund commented on Aug 5, 2025

    @MartinZikmund
    MemberAuthor

    This is still relevant for Skia Android

  8. MartinZikmund commented on Apr 8, 2026

    @MartinZikmund
    MemberAuthor

    Repro generator

    This issue was classified as not reproducible with a code sample or test.

    Reason: Android-specific asset naming bug.

  9. changed the title [-][Android] Assets with the same name and different extension don't work properly[/-] [+][Android] Assets with the same name and different extension don't work properly [7.0 ][/+] on Aug 9, 2026
  10. changed the title [-][Android] Assets with the same name and different extension don't work properly [7.0 ][/-] [+][Android] Assets with the same name and different extension don't work properly [7.0][/+] on Aug 9, 2026
  11. MartinZikmund commented on Sep 2, 2026

    @MartinZikmund
    MemberAuthor

    Audit result: NOT STARTED in feature/breakingchanges (as of 0950717a0d7).

    The Android drawable key-collision bug the issue reports is unfixed on the branch — the lookup and retarget code are byte-identical to origin/master, only relocated by the unrelated Uno.UWP → Uno.WinRT project move. The fix exists as a stalled draft PR (#15891, targets master, blocked on a nine-patch regression) and is tracked, unchecked, as BC74 in the breaking-changes rollup.

    Remaining

    • Drawable lookup still strips the extension before resolving. src/Uno.WinRT/Helpers/DrawableHelper.Android.cs:48 (FindResourceId) computes its lookup key via AndroidResourceNameEncoder.Encode(System.IO.Path.GetFileNameWithoutExtension(imageName)), and :87 (FindResourceIdFromPath) does the same via Path.GetFileNameWithoutExtension(AndroidResourceNameEncoder.EncodeDrawablePath(imagePath)) — extension is discarded either way, so Image.png and Image.jpg still resolve to the same key. diff <(git show origin/master:src/Uno.UWP/Helpers/DrawableHelper.Android.cs) src/Uno.WinRT/Helpers/DrawableHelper.Android.cs returns no differences; git log --oneline --follow on the current path shows the only branch-side event is f0f1b2ae2a1 refactor: Move the WinRT project folder to src/Uno / c5cf7b5c32d refactor: Move Uno.UWP project folder to Uno.WinRT — a pure rename, no logic change.
    • Retarget task still writes the base name without disambiguating by extension. src/SourceGenerators/Uno.UI.Tasks/ResourceConverters/AndroidResourceConverter.cs:28 builds the physical file via AndroidResourceNameEncoder.EncodeDrawablePath(resourceCandidate.LogicalPath), and EncodeDrawablePath (src/Uno.WinRT/Helpers/AndroidResourceNameEncoder.cs:66-67) only encodes the directory/filename and appends the extension verbatim (encodedFileName + extension) — it does not fold the extension into the base name the way the issue's own suggested fix requires (e.g. Assets_Image_jpg.jpg), so two same-named, differently-extensioned assets in drawable/ still collide once Android resource compilation (aapt) keys by base name. This file is also unchanged vs. origin/master:src/Uno.UWP/Helpers/AndroidResourceNameEncoder.cs (diff returns no differences beyond the rename).
    • Fix PR is a stalled draft, not merged. gh pr view 15891 → {"isDraft":true,"mergeCommit":null,"mergedAt":null,"state":"OPEN"}, targeting master (not feature/breakingchanges), body reads "part of [SVG - Android] Failed to load SVG image - System.Xml.XmlException: Invalid character in the given encoding. #15866, closes [Android] Assets with the same name and different extension don't work properly [7.0] #9618". git merge-base --is-ancestor is moot since no merge commit exists to check.
    • Not moot under Skia-only either. specs/050-breaking-changes-rollup/spec.md:241-243 lists this as unchecked BC74 ("Android drawable extension in retarget keys"), explicitly noting: "Deferred out of Phase 5: draft PR [BREAKING] fix!: Include original file extension in retargeted drawables on Android #15891 still targets master and is blocked on the nine-patch (.9.png) regression it exposes. Not moot under Skia-only — Skia-on-Android still resolves drawables through this path." DrawableHelper is confirmed live (not dead code): the source generator wires it at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/AndroidResourcesGenerator.cs:80 (global::Uno.Helpers.DrawableHelper.SetDrawableResolver(...)), and it's also consumed by src/Uno.WinRT/Storage/StorageFile.Android.cs and src/Uno.WinRT/UI/StartScreen/Extensions/JumpListItemExtensions.Android.cs.
    • No migration-guide or PackageDiffIgnore entry — this is a bug fix, not an API removal, so neither is expected; a full-text grep -li for "drawable" across build/PackageDiffIgnore.xml and doc/articles/migrating-to-uno-7.md returns nothing, consistent with no behavior change having shipped.

    Caveats (not blocking)

    • The issue body itself proposes the exact fix (fold the extension into the encoded key, e.g. Assets_Image_jpg.jpg) — this is what [BREAKING] fix!: Include original file extension in retargeted drawables on Android #15891 implements, but its own regression (nine-patch .9.png handling) is the reason it never merged even to master, let alone this branch.
    • The issue carries a no-repro label from an automated repro-generator pass, and a 2026 comment from Martin Zikmund ("This is still relevant for Skia Android") confirming it is neither stale nor obsolete.

    Audit is code inspection against the branch worktree; no build or runtime validation was performed.

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

Metadata

Metadata

Assignees

Labels

difficulty/medium 🤔kind/buglow-hanging-🍒no-reproplatform/android 🤖project/core-tools 🛠️

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions