Xamarin Android Resource file not found
Asked Answered
S

6

16

I am building an Android App in Visual Studio. When I try to build the app referencing items in the Resources folder, I get one of two errors.

If I preface "Resource.Layout.[Id]" or "Resource.Id.[Id]" with the namespace for my project, I get this error:

The type or namespace name 'Resource' does not exist in the namespace '[app namespace]' (are you missing an assembly reference?)

If I don't preface the call to Resource with my namespace, it tries to access the default Android.Resource class and I get this error:

'Android.Resource.Layout' does not contain a definition for '[axml file]'

Has anyone run across this error before? I've been searching for a while and cannot come up with anything that seems to be wrong. The Resource.Designer file exists. I've deleted it and let it get regenerated. The Ids are in the Resource file, the project just doesn't recognize that the resource class is there at all.

Originally, the namespace for this application ended in "Android". Thinking that may be part of the issue, I've changed it to "_Android" and "AndroidApp", including changing the default namespace in the project properties and changing the namespace declaration in each file. However, this error persists through each change.

Setter answered 30/5, 2014 at 13:15 Comment(0)
P
33

This might happen when you add a new file and Visual studio sets it to the wrong build Action. I know this has happened me multiple times and can spend ages trying to figure out what going on. If you right click the file and see the Build action. this should be set to Android Resource. Hope it helps

Screen shot

Prothallus answered 30/5, 2014 at 15:51 Comment(1)
add just now, I had to clean the solution, restart visual studio, rebuild the project. and then, finally, my drawable was found.Ritchey
P
12

The namespace in your code and the namespace in solution explorer should be same.

Pacha answered 30/5, 2014 at 13:22 Comment(3)
I'm not sure what you mean by the namespace in solution explorer. Do you mean the namespace in the project properties window?Setter
yeah they should be samePacha
They are. I've updated that location and the code files themselves with each iteration.Setter
D
2

The only thing that worked for me was to close VS, completely delete all the bin and obj folders of the project, reopen it, and recompile everything. This was due to some problems when working from Visual Studio Mac and then opening the same project in a Windows computer.

Duologue answered 19/9, 2021 at 2:20 Comment(0)
L
1

in AndroidManifest.xml make sure that no names depending on other resources which no longer exist for Ex:

android:label="@string/app_name" so we have to go to our resources/string.xml

<resources>
  <string name="app_id">ssss</string>  
</resources>
Lynettalynette answered 25/4, 2017 at 11:51 Comment(1)
I tried using your suggestion but couldn't find the problem but I'm sure your answer was my issue. I rebuilt from scratch and instead of copying resources, styles, colors, values...all those particular type files I manually created them one by one, then copied over the code from previous project and my issue went away.Turkish
R
0

I came up to this problem and i solved it so simple:

1- Clean your startup project

2- Build one more time for android.

That's it.

Retread answered 17/10, 2022 at 7:16 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Beano
D
0

Just delete the bin and obj folders from Projects file. Then relaunch VS

Daladier answered 21/9, 2023 at 11:42 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.