To use Xamarin, or not to us Xamarin?

Update: I just installed the XamarinInstaller on my computer at work…Works out of the box.

Update on and update: I’ve started a series on making an app with Xamarin.

That has been a very good question.

After the announcement that Xamarin was going to be free for everyone, we were really excited to have a look and try this out. The weekend is always a good time for some research and development. It won’t take that much time, to go over the possibilities, and dream a little of what we could accomplish with it, surely.

WRONG!!!

To say it spoiled my weekend, is just a bit of an understatement. I had to switch Cortana off with all the profanity I was yelling at my computer.

Enough of a back-story, let’s dig into the juicy bits.

The Beginning

Having downloaded the XamarinInstaller once it’s executing it will tell you what it needs, you have some options to change certain locations where you’re Android SDK is, it will install the templates into Visual Studio, and then it’s done. A browser window will open and take you to their video tutorials. Pretty straight forward.

To be honest, I was too excited to watch any videos, but I kept the tab open on the link to ‘Introduction to Xamarin.Android’, just in case. The little byline that says ‘Learn how to use your C# skills to develop Android apps, no Java required.‘, gets me all excited. Little did I know that is was a sham!

Okay, so giddy like a little kid on xmas, I opened Visual Studio and pointed it to start a new project:

01. Start

Sweet!

At this point I just want to see it work, dig into the project, and look at the code, so I press OK.

02. Project Layout

As you can see, a very basic layout, with some folders and names for documents that seem a little familiar. So far so good. After this, I start up my AVD Manager, and launch a virtual device. Visual Studio sees it, and I can build and deploy to this device. Right? I mean I haven’t changed anything, this is just the standard base structure of a new App.

WRONG!!!

03. Error

Okay, great start. I am immediately hit with two/three errors:

“aapt.exe” exited with code -103741819.

And.

The file “obj\Debug\android\bin\packaged_resources” does not exist.

Opening the file Xamarin.Android.Common.targets on the line mention in the Error List gets me this:

MoreErrorAlready

All right so I commented it out and tried again. Again, no go, this time I get a slightly new error, which at the time I didn’t pay too much attention too.

java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0

Remember where it said I didn’t need Java?

The Middle

Like I mentioned earlier the UnsupportedClassVersionError error was ignored by me, because as soon as I saw it, I uncommented the code again, going back to the previous error. Now, I still had the tab open with the video tutorial, and I downloaded the MATERIALS:

04. Materials

I opened the project in Visual Studio, and hit build:

05. Run Error

What did I do to deserve this?!?!?!

Now I can obviously no longer ignore the error. Having done my fair share of Java programming I know what the problem is here. So I have a look at the installed JRE and JDK, and they are indeed mismatched, so I make sure that they are both at least 8.

IMPORTANT! Please make sure that you also install the 32bit versions of those, because only after I installed the 32bit version would this problem go away.

Under ‘Tools > Options > Xamarin’ in Visual Studio 2015 you get the below screen:

06. Options

Having changed all that, I built the project, and I got the “Build succeeded”, the virtual device was still running so I went ahead and deployed:

07. GdbServer

Unable to start debugging. Non-debuggable application installed on the target device. Required file ‘/data/data/My.Application/lib/gdbserver’ could not be found on the device. Please install a debuggable version.

The End

At this stage, I am ready to throw in the towel, but just to prove a point I opened Android Studio, created a new project, run it in the virtual device, and without a squeak it popped up on the screen.

Why can this just not work out of the box? Perhaps it was just never meant to be…

Now, I am not one to give up, I have to get this working.

Using a bit of Google-fu I found out that it had to do with the Debugger that was in use. The Microsoft one for Android uses native code to build the apps, and since we’re using Managed Code to build these apps with Xamarin, it has an issue with that.

Right click your project and hit Properties:

09. Solution

Select the Xamarin Debugger!

08. Finally

IT WORKS!!!

So I fire up the default app I created previously, and again I am hit with the following error:

The file “obj\Debug\android\bin\packaged_resources” does not exist.

This time I have both the apps and decide to have a look at the differences. I open up the AndroidManifest.xml, and I don’t mean the on under the Properties visible in the Solution Explorer. Oh no, I mean the one under ‘TipCalculator\obj\Debug\android\manifest’. Nothing really looked weird or suspicious. So I looked at the structure visible in Solution Explorer.

ExhibitA

Just out of curiosity I deleted the drawable folder from the App1 application. I got an error that it couldn’t find the icon file. So I copied the folders from the TipCalculator app and added them to the App1 project. I deleted the single drawable folder, and guess what? Yes. It worked.

Conclusion

If I was new to all of this and I ran into these kind of problems, I might get very discouraged by this. It will be a while before I would use Xamarin in production, as this is just ridiculous from any stand point. Google’s Android Studio pretty much works out of the box. It’s a very solid piece of software that gets a lot of love and care from a dedicated team that brings out solid updates and improvements. If Microsoft is serious about supporting the other platforms outside of their little circle of products than they would have to spend some serious time on making sure this works out of the box.

Thanks for reading, and I hope this can be of use to some people!

Advertisements

One thought on “To use Xamarin, or not to us Xamarin?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s