简体   繁体   中英

What is the difference between XML and AXML in Xamarin.Android Apps?

Since VS2019, I have noticed that every new project has regular XML as its resources like native Android Studio applications, but previously (2015 or 2017) it created AXML files.

Internally, the files looked exactly the same, but recently I'm getting new bugs in Xamarin.Android in each new release in VS2019 (Windows or Mac), for example:

Perhaps, I should use AXML files as an uncommon comment came yesterday:

The linker removes classes that are needed and apparently doesn't parse the axml to see that they are in fact needed

This situation makes me wonder if there is any specific difference between them because when I run my app it works perfectly fine while it's not for Release or certain configurations like linking all assemblies .

Important note:

As my title of the question says: I'd like to know the difference between both extensions since for any reason the extension changed without any notice. The previous situations only raised my curiosity about this situation, they are not necessary linked.

.axml is nothing more than an extension hack that was used to render Android Layout Files ie Android flavored .xml files inside Visual Studio . It literally meant .axml (Android XML).

We previously lacked infrastructure to interpret flavored versions of .xml files coming from all different types of workloads. However in 16.2 and 8.2 respectfully (Visual Studio and Visual Studio for mac), you can use .xml seamlessly in your application and be provided a layout editor, rich intellisense, and more.

If you don't require a layout editor, you have been able to use .xml since the first release of MonoDroid as .axml is processed the same way as .xml at the end of the day.

First, the linker does not do anything with your layout files. So .axml or .xml, it just won't touch it or parse it. The linker only work with the classes represented by the layout files, not the layout files themselves.

Now, regarding the ".axml" versus ".xml" I believe the ".axml" extension is just a legacy thing from MonoDroid. The only goal of that specific extension was probably to identify android layout files, from regular xml files, without any advanced logic (it's only a supposition).

Long story short, if you're facing issues in your project regarding the linker, it's probably not related to your extension choice for layout files. You should keep whatever Visual Studio defines as the default.

First of all, Link all assemblies is prone to crashing and while those crashes can be fixed with some level of effort and knowledge, exactly because it causes more trouble than what it helps it isn't recommended option by Xamarin. So those are not 'bugs', those crashes are expected behavior.

Second, that comment on github that you linked doesn't tell there is any problem with axml files. It says that your axml file requires some library to be present and that it cannot be determined by the compiler which removes it and causes crashes.

Basically it has nothing to do with the question in your title.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM