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:
Link assemblies is crashing
Build with Linking is Crashing in Xamarin.Android 9.5
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 i.e. 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.
Related
Noob Android Studio 3.6.1 on Mac Mojave developer here. I have a very simple app with a few activities. Every so often, the Kotlin class for one of the activities will complain of an unresolved reference to the corresponding layout XML file.
For example, in the Kotlin Class (TraceActivity.kt), I have the following code:
setContentView(R.layout.activity_trace)
and the corresponding XML file lives at:
MyApp/app/src/main/res/layout/activity_trace.xml
All pretty standard stuff I reckon. But setContentView would complain that it couldn't resolve activity_trace. This has happened on a few occasions, and I discovered that restarting would resolve the problem. But this morning, it isn't helping. And it's also started complaining about some of the strings I've added to strings.xml
I managed to get round the errors by making use of the full names for each of the items e.g.
com.mysite.myapp.R.layout.activity_trace
and
com.mysite.myapp.R.string.my_message
So my guess (as a noob) that somewhere it's losing track of where it is. And yet my other activities are perfectly happy when I omit the full location. Can anyone offer some insight here? Thank you - SO is awesome.
I started using Visual Studio 2017 Enterprise Edition with Version 15.7.4. and Xamarin Version 4.10.0 and need to work on Xamarin native android application.
But Auto fill suggestions not coming in xml and axml files. Intellisense working for widget names(Like TextView, EditText etc.) In layout axml files. But, for widget properties (Like android:layout_width, android:gravity etc.) it isn't working. Where as in styles.xml, menu.xml suggestions not coming at all. I check with following ways.
1) XML - Schemas > android-layout-xml.xsd and schemas.android.com.apk.res.android.xsd files are exists
2) File opened as XML (Text) Editor
3) I didn't find Resharper in Tools
Also, Is there any way to change Xamarin keyboard shortcuts to Android Studio or Eclipse?
Being a Xamarin developer for almost two years I have come to terms with the fact that the Xamarin Android intellisense has never worked as it is expected.
It has a lot of bugs and issues (Links below) which have made it a real pain in the neck, But there are workarounds which you have already mentioned above and if those do not work for you trust me nothing will.
https://forums.xamarin.com/discussion/118384/android-designer-does-not-work-well
https://forums.xamarin.com/discussion/125879/designer-not-loading-layout-at-all
https://forums.xamarin.com/discussion/76851/visual-studio-2015-android-designer-not-working
https://forums.xamarin.com/discussion/82082/android-designer-not-working-in-visual-studio-enterprise-2015
https://forums.xamarin.com/discussion/6258/android-designer-doesnt-work-in-vs-2012
https://developercommunity.visualstudio.com/content/problem/99268/xamarin-android-designer-not-working.html
My suggestions:
Android studio provides you with a very strong designer and hence I would simply suggest you use Android studio to write down your XML and then just copy paste it to your Xamarin AXML/XML files and it should work like a charm, Same can be done for any other time of files such as strings or styles XML.
For changing the visual studio shortcuts you can simply check the following guide
I am implementing menus using TWL (http://twl.l33tlabs.org/) in an app written using Libgdx. The app runs fine if I don't start any menus, but as soon as I go to a menu screen it immediately force-closes. Menu screens work fine on the desktop version.
In which build path should TWL-android.jar be included (right now it behaves the same in main, android, and both)? And how will the program know to use the libraries from this .jar instead of the default gdx-twl.jar? Will I have to manually implement something in code to use one or the other depending on platform?
There does not seem to be any documentation or sample code of anyone using TWL on android, only mentioning that it can be done.
Running debugger attached to phone gives the following logcat error:
Could not find class 'com.badlogic.gdt.twl.Layout' referenced from method com.Nanners.OptionsScreen.<init>
I think that TWL-android.jar should be added to android project's build path too. Location of .jar is not relevant.
When you add TWL-android.jar. As that is Android specific you can't use it on the core project, so the classes you are importing are the ones from gdx-twl. To make it simpler to explain I will divide it in different escenarios.
You add TWL-android to your Android buildpath. But you use Gdx-twl in your core project. Which isn't added. Thus getting a:
Could not find class 'com.badlogic.gdx.twl.Layout'
You add both TWL-android AND Gdx-twl to your build path. Thus getting duplicated classes and:
Conversion to Dalvik format failed with error 1
Solution
If you use TWL-android classes, you can only do it inside the Android project:
Merge Core, Desktop and Android project. Or
Use Interfacing with Platform Specific
If you use Gdx-twl:
Don't do it.
Actually the best solution is to get rid of all twl stuff and use Scene2d.Ui instead. Its crossplatform and much easier to use.
I'm developing an API for Android and it works great but I'm not sure how to package/distribute it. I've gotten the "meat" of the API into a jarfile - that's all the classes and an XML file in res/values/attrs.xml (I'm not sure if there's a way users can reference to that without having to copy my attrs.xml into their /values folder, but that's another question).
While trying my API in a test case, I've added my .jar to the build path and I can import a class successfully if I want to, but I don't want to :P My API allows users to implement a custom View into their own XML files, so nothing is instantiated in code.
The question: How can users reference to a custom View in my API? For example, if my View is called FooView and is in package com.myfoo, the following XML fails to load:
<com.myfoo.FooView
android:layout_width="fill_parent"
android:layout_height="100dp"
/>
Does this have to packaged into a jar , As i see facebook android sdk they give out the source code . I set it up as a new android project and from my android project reference this as library.In that case i am able to access all the apis exposed
You might want to look into Android Library Projects. These are basically normal android projects, which can be referenced as a library. This means you can define classes, layouts and resources as you would normally, and just use them in your main app (in this case in your clients app) as if they were defined in the same project. This allows you to reference views in XML like you tried above via <packagename.classname ... />.
There is one huge downside though (which is especially important when you create custom views):
styleable-resources simply don't work. This is a bug.
According to this question it's going to be fixed in the next devtool release though.
With that in mind I recommend setting up a small test project with a test library project and see if everything that you need works correctly.
I'm new to android programming, but one thing that I can't seem to get down is writing the XML files. I use a program called droiddraw to help generate the xml code. This program is very simple because it lets me add buttons and DRAG them where I want them. Once I get the screen/form (or whatever it's called) setup the say I like, it will generate the the xml file for me. My question is this: "Does eclipse have a plugin that will do that too?" I know that I can view the form/screen that I can designing, and add buttons and such, but I can't drag them to where I want them. I always have to edit the layout values manually.
The xml layout editor that ships with Eclipse is pretty woeful. Thankfully Google are putting effort into improving this so that we have a more seamless drag n drop experience. You can download and compile the latest works here http://tornorbye.blogspot.com/2010/11/building-android-ide-tools.html
or just wait a week (or two) for Gingerbread to be released. A stable version is sure to be included in the Eclipse ADT update that is released then.
ADT is nicely integrated into Eclipse for Android development.