'Unexpected element <uses-library> found in manifest
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.
Solution 1:[1]
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 !!
Solution 2:[2]
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.
Solution 3:[3]
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.
Solution 4:[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.
Solution 5:[5]
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".
Solution 6:[6]
just use uses-library inside tag under android manifest file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | M Salman |
Solution 2 | Joachim Haglund |
Solution 3 | cmw2379 |
Solution 4 | Mac |
Solution 5 | Cueball 6118 |
Solution 6 | Muhammad Mukthayar |