Xamarin: Getting error while building -> invalid file path 'obj\Debug\90\res\views\layouttest.xml'

Viewed 6570

While I'm trying to build my Xamarin App, it stops everytime with the error message "invalid file path 'obj\Debug\90\res\views\layouttest.xml'". I tried to delete the directory, rebuild or clean the solution and build it again. The error comes from the Android Project. The file that is marked from VS is in the directory: Directory Output

Update: As Land Lu - MSFT mentioned below, was an unused file the issue. Deleting the file and rebuilding the project worked just fine!

3 Answers

It seems there is a cache file named layouttest.xml in your project. Try to remove the file there if you don't need it.

Delete the bin/obj folders of your project to make a full cleaning. Finally, rebuild your project to complete the compiling.

If you are finding this error after updating VS2019 to 16.7.2 please see the following articles: https://developercommunity.visualstudio.com/content/problem/1156349/index.html https://github.com/xamarin/xamarin-android/issues/5052

The TLDR is that android resources now have to be present in standard folders such as Resources/layout and Resources/drawable. Using random folders within your project will generate build errors.

Just to add to the fun, I had a resource that had somehow ended up as the dependent of another file.

<AndroidResource Include="Main.axml">
  <DependentUpon>CanvasRenderContext.cs</DependentUpon>
</AndroidResource>

I had to edit the csproj file to remove the DependentUpon tag before I could move to Resources/layout folder. Hopefully you wont have an issue quite that weird.

For those hitting this from the MAUI side as I was - my issue was that I had an image resource file that was not added to the project correctly. Looked at the properties for the image in Solution Explorer and it was still an Android resource rather than a MAUI image. Guess this makes sense, was migrating the image from a Xamarin Android app. Had some lines in the project file explicitly removing it from the MAUI image category and adding it to the Android resource category. Looked something like this:

<ItemGroup>
  <MauiImage Remove="Resources\Images\foo.png" />
</ItemGroup>

<ItemGroup>
  <AndroidResource Include="Resources\Images\foo.png" />
</ItemGroup>

Removed those lines and the image was correctly recognized as a MAUI image, and the issue went away.

Related