dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.96k stars 1.7k forks source link

Not easy to add a "AndroidResource" to a maui project and `Resource` is ambiguous #9877

Open mattleibow opened 1 year ago

mattleibow commented 1 year ago

Description

To play a sound when earn an achievement, you need to write platform specific Android code and give the SoundPool object an Android Resource Id. To schedule a local notification/alarm, you need to give an Android Resource Id for the badge image and custom sound file.

I am unable to find any documentation on managing Assets so that they generate an Android Resource Id in the Resource.designer.cs file. When adding a .wav file into the Maui raw asset folder the default build action will not generate the resource id. When adding a .wav file into the Platforms/Android/Resources/Raw folder the default build action doesn't generate the resource id.

Also, Visual Studio 2022 does not give good hints for the Resource namespace.

'Resource' is an ambiguous reference between 'Microsoft.Maui.Controls.Resource' and 'Microsoft.Maui.Graphics.Resource'

This list should include [App Root Namespace].Resource. Again, there is no documentation anywhere on how to access the Android Resources for platform specific code.

The main issue is that AndroidAsset is for the "assets" but we need a way to add RAW resources.

Steps to Reproduce

  1. Create new Maui Project
  2. Add a test.wav file to the Maui Resources/Raw folder (do not set a build action)
  3. In a platform specific file in Android platform code
  4. "int test = Resource.Raw.test;"
  5. Try to figure out how to make this line work.

Link to public reproduction project repository

:)

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

All

Did you find any workaround?

The current workaround is to manually add the file to Platforms\Android\Resources\raw and then use AppNamespace.Resources.raw but this is not intuitive nor documented.

Relevant log output

No response

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

mattleibow commented 1 year ago

@davidbritch what is the docs for this? Could we maybe add this to the docs for how to access platform resources? Like android raw or xml.

mattleibow commented 1 year ago

Maybe we could add some specific Maui* items in the list. MauiSound or MauiMedia something that could be put in the right place and some xplat player could be used. This could be for audio/video like wav, mp4 etc.

This could also be extended for other things like MauiMLModel and stuff like that for any ML/AI models. iOS has a munch of build actions that we could compare with.

scottkdavis commented 1 year ago

Following

dansiegel commented 6 months ago

It would be great if this could get some attention. This absolutely is affecting app migration from Xamarin apps as it breaks code in native services that need to reference resources.