xamarin-macios icon indicating copy to clipboard operation
xamarin-macios copied to clipboard

Loosing icons and images when using xcassets in libraries

Open mandel-macaque opened this issue 5 years ago • 9 comments

Steps to Reproduce

  1. One solution containing two or more projects
  2. An app project (multiplatforms), using Xamarin.Forms
  3. A library project (multiplatforms), using Xamarin.Forms

In the app project, under iOS, fill the Assets.xcassets with app icon and a new Media.xcassets with images.

In the library project, under iOS, add a nex XXXX.xcasset file and add images in it.

Make sure that the app refers to the library and then build it.

Expected Behavior

Images added to the assets are present.

Actual Behavior

The application loses its images, the app icon as well as other assets that were in xcassets folder.

Move the images outside the xcassets, put them in the Resources folder, delete the xcassets file and rebuild. App icon and images are back.

Example Project (If Possible)

listviewtest.zip

This is from a feedback issue

mandel-macaque avatar Mar 11 '19 21:03 mandel-macaque

Please fix this bug. We wasted two days trying to figure out why the app icon magically stopped showing.

LuizGsa21 avatar Sep 26 '19 17:09 LuizGsa21

This issue needs to be classified as a bug because if you add a nuget package that uses xcassets, your app is no longer deployable since the app icon will always be missing.

LuizGsa21 avatar Sep 30 '19 16:09 LuizGsa21

Any updates here? this is not just for ios, this but is also actual for androin app.

MrSerWin avatar Jan 25 '21 12:01 MrSerWin

Here is a recent repro using net6.0 https://github.com/J-Swift/net6-assets-repro

J-Swift avatar Sep 01 '22 16:09 J-Swift

See also https://github.com/xamarin/xamarin-macios/issues/6095.

rolfbjarne avatar Sep 26 '22 21:09 rolfbjarne

For what it's worth, I was blithely unaware of this issue (for years) on using Xamarin because my class libraries were packing PNG images as BundleResource items. Moving to dotnet, that is not working - my MAUI app is not seeing the BundleResources from my class library.

Does anyone have a workaround for distributing multiple sizes of PNG images from a class library or a nuget? I think I could pack MauiImage items per something like https://github.com/dotnet/maui/issues/10019#issuecomment-1248032520 but it doesn't seem like I can get multiple sizes of the same file (2x,3x, etc). It's either SVG or bust to get the assets useful for different DPIs, I guess?

gkarabin avatar Jul 15 '23 11:07 gkarabin

Maybe the best compromise is to distribute only the highest-resolution image available, setting BaseSize appropriately, and letting MAUI resize the image? With the .targets file set appropriately per @Redth's awesome suggestion at https://github.com/dotnet/maui/issues/10019#issuecomment-1248032520, it should all come together.

gkarabin avatar Jul 15 '23 12:07 gkarabin

I had a look at this, and it seems there's a significant amount of work in order to fix it.

  1. When the library is built, we compile xcassets into an Assets.car file, and embed the Assets.car file.
  2. When the app is built, we pull in the Assets.car file from the library, and then compile the app's xcassets to its own Assets.car file.
  3. Both are copied to the same location in the app bundle. The library one seems to be the one that wins.

The problem is that there doesn't seem to be a way to merge to Assets.car files, which means the solution would have to be to embed the original xcassets resources in the library as opposed to the compiled version, and then we can consume those resources when the app itself is built.

Hopefully there are no important reasons to compile assets for library builds (as far as I remember it's always been that way), so we could add support for embedding the original resources instead. One consequence is that libraries/nugets would have to be rebuilt in order to work.

One stop-gap measure we could take would be to detect the problem at build time and issue a warning.

rolfbjarne avatar Aug 16 '23 16:08 rolfbjarne

I've filed two new issues that would be stepping stones to fixing this:

  • https://github.com/xamarin/xamarin-macios/issues/19028
  • https://github.com/xamarin/xamarin-macios/issues/19029

rolfbjarne avatar Sep 14 '23 14:09 rolfbjarne