matmork / rive-maui

Rive animations in Maui using iOS/Android runtimes
MIT License
6 stars 1 forks source link

Should riv files be put in `Resources/Images`? #2

Closed hansmbakker closed 7 months ago

hansmbakker commented 7 months ago

Hi, Super cool to see the progress you're making!

I had a question about the guidance to put the riv files in the Resources/Images - if files are put there then they are automatically marked with the MauiImage build action which might call resizetizer on them and maybe other side effects.

What were your considerations of this vs putting those files in the Resources/Raw folder?

matmork commented 7 months ago

Thanks! 😄

I would hope the resizetizer only touches compatible image formats. I agree this is not the best place and I originally put them in the Resources/Raw folder but was unable to get the identifier in Android. See RiveRenderer.cs#L43 tried with "raw" instead of "drawable" but still returned 0. iOS was fine.

If you have time, maybe you can look at it?

hansmbakker commented 7 months ago

It looks like putting them in the Images folder is the way that will work (unless you want to create your own MSBuild task which I doubt :) )

So I looked into it - the explainer file in the Resources/Raw folder says that MauiAsset files need to be used with FileSystem.OpenAppPackageFileAsync(string filename).

This function calls Application.Context.Assets.Open(filename); which points out that it does not use Android Raw Resources but Assets.

The Android documentation `says:

However, if you need access to the original filenames and file hierarchy, consider saving resources in the assets/ directory instead of res/raw/. Files in assets/ aren't given a resource ID, so you can only read them using `AssetManager .

So it looks like putting a file in the Resources/Raw MAUI folder (marking them as MauiAsset) does not result in those files getting a Resource Identifier.

hansmbakker commented 7 months ago

@matmork for the sake of completeness:

The correct location for Android raw resources is Platforms/Android/Resources/raw. They must also have a build action of Androidresource (this should be the default for Platforms/Android/Resources/**/*.

(See https://github.com/dotnet/maui/issues/10580#issuecomment-1279294398)

I see she building an app where users want to include a Rive file on all platforms, having them in one location (like the Resources/Images folder) is more practical

matmork commented 7 months ago

@hansmbakker Thanks for your research! Learnt something new.