Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Android Xamarin colors.xml not found

I’m converting my Xamarin app (for Android) to .NET 8. The app source code in Resources/values has these files:

colors.xml:

  <resources>
        <color name="colorPrimary">#DD5706</color>
        <color name="colorPrimaryDark">#1B3147</color>
        <color name="colorAccent">#8167E6</color>
       
      <color name="white">#ffffff</color>
      <color name="darkwhite">#EFFFFE</color>
      <color name="transparent">#00ffff</color>
      <color name="semitransparent">#880000</color>
      <color name="orange">#ff8800</color>
      <color name="light_orange">#e27d18</color>
      <color name="light_blue">#87CEEB</color>
      <color name="black">#000000</color>
      <color name="menuButtonColor">#ea8e44</color>
      <color name="btn_normal">#ea8e44</color>
      <color name="pressed_color">#e27d18</color>
      <color name="default_color">#f8f1e7</color>
      <color name="selected">#f8dcd3</color>
    </resources>

And in the drawable folder is background.xml:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<selector xmlns:android="http://schemas.android.com/apk/res/android">    
  <item android:drawable="@android:color/background_light" android:state_pressed="false" android:state_selected="false"/>      
  <item android:drawable="@color/orange" android:state_pressed="true" android:state_selected="true"/>      
  <item android:drawable="@color/light_blue" android:state_pressed="false" android:state_selected="true"/>    
</selector>

Yet when I build the app I see a series of errors like this:

resource color/orange (aka com.xyz.MyApp:color/orange) not found.
 

Someone suggested I add this to the csproj file:

<ItemGroup> <AndroidResource Include="Resource Path" /> </ItemGroup>

And apologies if this is duplicative of a question I posed yesterday.

>Solution :

To resolve this issue, ensure that your resource files (colors.xml and background.xml) are properly referenced in your project configuration.

Confirm Resource Files:
Make sure colors.xml is located in Resources/values and background.xml is in Resources/drawable within your project directory.

Update .csproj File:
Modify your .csproj file to include these resources:

<ItemGroup>
  <AndroidResource Include="Resources\values\colors.xml" />
  <AndroidResource Include="Resources\drawable\background.xml" />
</ItemGroup>

Adjust the paths if your files are located differently.

Clean and Rebuild:
After updating your .csproj file, clean and rebuild your project to ensure all resources are correctly included:

Clean Solution: Right-click on your solution in Visual Studio and select "Clean Solution."
Rebuild Solution: After cleaning, right-click again and select "Rebuild Solution."
Verify Resource References:
Double-check that references in background.xml like @color/orange and @color/light_blue match the color names defined in colors.xml.

This should resolve the resource not found errors and ensure your Xamarin app transitions smoothly to .NET 8.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading