Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Android Resource file not found

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.

like image 733
rwakelan Avatar asked May 30 '14 13:05

rwakelan


4 Answers

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

like image 163
InitLipton Avatar answered Nov 15 '22 09:11

InitLipton


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

like image 24
user3674052 Avatar answered Nov 15 '22 11:11

user3674052


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.

like image 3
benjamingranados Avatar answered Nov 15 '22 11:11

benjamingranados


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>
like image 1
Abdullah Tahan Avatar answered Nov 15 '22 10:11

Abdullah Tahan