Android-specific code on MAUI: Trouble with Android.Resource

Kleber Ferreira 0 Reputation points
2025-03-11T17:26:09.4233333+00:00

What I am trying to achieve right now is something I've done before in other prototypes where I work, but I haven't run into this problem so far. I will give as much context as possible without making this question too long.

Our app will use ARCore on Android and ARKit on iOS, while having other parts of the app be handled by MAUI's codebase under the MVVM architecture. We prototyped the use of ARCore+OpenGL on MAUI and Xamarin.Forms before, following a sample code from Xamarin's github.

I placed a .xml layout inside Platforms\Android\Resources\layout called ar_layout.xml, with Build Action set to AndroidResource. When trying to reference that ar_layout file in the code I get this error:

"Resource.Layout" does not contain a definition for "ar_layout"

User's image

By the way, that line reads 'Droid.Resource.Layout.ar_layout', because if I write 'Android.Resource' the compiler thinks I mean the Platforms.Android namespace, when in fact I mean to access the actual Android namespace. So I put this on the 'using' statements:

User's image

The same problem happens in other classes where I try to reference some shaders for OpenGL:

"Resource.Raw" does not contain a definition for "object_vertex"

object_vertex.shader is a file located under Platforms\Android\Resources\raw.

I tried changing the build action to AndroidAsset and None, tried Cleaning and Rebuilding, tried Re-opening VS2022, and nothing worked.

And like I said, I've done this before in other prototypes, using .NET 8 just like I am right now, but this is the first time I get such errors.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,994 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.