8

I am using org.apache.legacy library in my xamarin project. I have added <uses-library> tag in my manifest file but I get an error while building the project which says:

Unexpected element <uses-library> found in manifest.

Also when I try to comment that line, it comes back while building the solution.

halfer
  • 19,824
  • 17
  • 99
  • 186
M Salman
  • 170
  • 1
  • 11
  • And what does your manifest look like? i.e. https://stackoverflow.com/questions/54618714/xamarin-google-maps-apps-targeting-android-pie-are-broken#comment96030332_54618714 – SushiHangover Oct 10 '19 at 09:57
  • I am sorry my code is not properly formatted. I am posting the question for the first time. – M Salman Oct 10 '19 at 10:02
  • Build error says that "Unexpected element found in manifest" and when I check the error line, it is Line 10 but uses-library tag is at line 9. I am so confused about the behaviour. – M Salman Oct 10 '19 at 10:03
  • My tag is outside application tag. But when I cut it and paste it inside application tag and build the solution, Visual Studio picks that line again and place it where it was. Any idea why it is happening? – M Salman Oct 10 '19 at 10:18
  • you cant format code in comments, so you need to edit your original question and then use the "{}" button on the editor to make the code formatted within the post. – Joachim Haglund Oct 10 '19 at 12:55
  • I'm having the same issue @MSalman and I'm using Visual Studio for Mac. It started happening for all developers on a project I'm on after updating VS. I'll post here if I figure anything out, but I've also tried a bunch of stuff with no luck so far. My current guess is that the manifest is just generating wrong due to some project configuration issue. My bet is that this is a bug in the build process in the newest version based on specific project settings. Otherwise, more people would be complaining about this. – ChristopherW Oct 14 '19 at 14:15

6 Answers6

14

uses-library tags should be placed within the application element, that's why you get the error.

the problem with the compiler complaining about the same line even if you change it can most likely be solved by restarting Xamarin studio, and then cleaning the project and rebuilding.

Joachim Haglund
  • 775
  • 5
  • 15
  • Yeah this is definitely the issue, but Visual Studio is currently generating the Manifest that way which is weird. So you have one half of the answer which is appreciated. In my manifest, it adds the apache uses-library tag both outside the Application element and inside the Application element which is the problem. Something about the newest version of VS does this. Restarting VS/the computer/updating/cleaning solution doesn't solve the issue. Potentially going to try clearing the local program cache and or reinstall VS to see if that corrects it. – ChristopherW Oct 14 '19 at 14:18
5

Ok, so one of my co workers found the solution to this, but it's weird. So, for context we use Visual Studio for Mac so this might not be 100% compatible with Windows. The issue we found was that Visual Studio has several different views for the AndroidManifest.xml file and one of the views was modified at some point in the past.

  • The default view is the UI based one with inputs and what not to help working with the file.
  • The second view is when you right click the manifest file and use OpenWith -> 'Source Code editor'. This view is a minimalistic view of the manifest in xml that can be edited. In here you should also find the problem line about the apache library that is not in the application tag as it should be. So, you can remove it here.
  • The third view is the generated manifest and can be found by following the error messages outputted by the IDE about the uses-library tag.

Manifest UI View -> Manifest intermediate xml view -> Manifest generated file

It seems that you can only modify one version of the manifest file in xml since the other will always overwrite your changes. By following the error message you only get to the final output and not the intermediary Manifest that can actually be edited and maintain its changes. There was a modification to the manifest a long time ago in our project that is just now throwing errors with the newest release of Visual Studio.

The suggested fix is to not follow the error message to open the Manifest and instead open the manifest file in xml raw. It will be a smaller file than the generated one so look for that to know you're in the right place. Remove the uses-library line that is incorrectly placed outside of the Application tag and save. Hope this helps somebody else cause it definitely caught me up for a few hours.

ChristopherW
  • 993
  • 1
  • 12
  • 25
4

So after spending few nights on this stupid bug, I created a whole new app from scratch and configured/installed all the packages and SDKs for using Google Maps in Xamarin android native and this time I put the tag inside the application tag and installed the app on my device and it worked absolutely fine. Hope it helps !! Cheers !!

M Salman
  • 170
  • 1
  • 11
4

Simply removing the uses-library tag and placing it inside application tag by editing the manifest file using Notepad++ fixed this issue for me (Inspite of clean, rebuild etc..,).

Somewhat similar to what @cmw2379 said.

Mac
  • 373
  • 5
  • 20
  • This suggestion worked for me. I closed VS2019, edited the manifest in NotePad++ and the error was resolved back in VS. – paparush Dec 08 '20 at 02:05
  • yes, for some reason removing the uses-library tag inside VS is adding that line back during build. Hope you faced it too.. :) – Mac Dec 08 '20 at 07:35
0

This is a fairly common one (or at least it's caught me out more than once).

When Visual Studio compiles and runs your code it will do it from (for example) /bin/Debug/netcoreapp3.1

For some types of files you have to tell VS to copy it into this "working folder" or output directory. It tends happen a lot with appSettings.json config files and causes confusion, which in this case it's a very similar situation.

Find the file in VS, right click go to properties and change the value of the "Copy to Output Directory" field to either "Copy always" or "Copy if newer".

Cueball 6118
  • 517
  • 4
  • 16
0

just use uses-library inside tag under android manifest file.