Get Started: Using Xamarin, a Cross-Platform Development Software
A primer on cross-platform mobile app development using Xamarin.
In the 1990s, James Gosling and a group of computer scientists at Sun Microsystems faced a challenging programming problem.
They were developing C++ code to run on set-top-boxes, the little black boxes that sit on top of your television for Cable TV. However, the software on each of these boxes ran on a slightly different platform, forcing developers to re-write the code for each system.
Out of this struggle came the concept of “write once, run anywhere” or WORA for short. More importantly, Gosling and his team at Sun proposed to solve this programming language problem.
Their efforts eventually led to Java, universally known today for its ability to run on a variety of computers and devices.
Mobile App Industry Discovers Xamarin
Fast-forward 20 years and the mobile app industry found itself facing the same dilemma.
Let’s say you were a developer, creating apps for the Apple iPhone. That meant you wrote code using a language called Objective-C with a tool called Xcode.
Now let’s say you came up with a great app idea, wrote the code and it sold like hot cakes on the App Store.
Typically, after this happened, you would shift your focus to the Android market, which makes up roughly half of all smartphones sold. If you wanted to play in this market, your app would have to be completely re-written for Android using (ironically) Java.
Around this same time, Miguel de Icaza was working on porting the Microsoft .NET run-time environment to run on Linux. De Icaza was not initially focused on the mobile app space, but as his work on Mono (a platform that allows .NET apps to run on a variety of systems, including Linux, OSX, Android, and iOS) evolved, it became apparent that C# code written for .NET could (in theory) run on both Apple’s iOS and Google’s Android.
Mono would eventually form the basis of Xamarin, a cross-platform development environment.
In this blog, we’ll explore the details of Xamarin, including:
• What is it?
• Who is the intended audience?
• Why should I care about it?
• What are the associated costs?
• When and where can I get training?
• How do I get started?
If you made it this far, fasten your seatbelt; you’re about to embark on a tour of Xamarin and all that it has to offer for cross-platform mobile app development!
What is Xamarin?
In March of 2016, Microsoft officially acquired a software company called Xamarin, pronounced like Tamarind with a “Z” and without the “D” at the end or zæmərɪn.
Xamarin is a platform for developing mobile applications using C# and .NET Frameworks. Both Google Android and Apple iOS apps can be built using Xamarin.
There are several products under the Xamarin umbrella:
- Xamarin platform:
- Xamarin.iOS – the native iOS frameworks packaged in a Xamarin wrapper
- Xamarin.Android – the native Android frameworks packaged in a Xamarin wrapper
- Xamarin.Forms – a set of portable controls that are mapped to native Android and iOS control
- Xamarin Studio – an integrated development environment (IDE) where developers type in their code and build mobile apps using C#
- Xamarin Test Cloud – a test environment that allows developers to test mobile apps
- Xamarin (Android) Player – a simulator that allows developers to test (Android) apps without using a real device
- Xamarin University – a place for developers to learn and become certified in the ways of Xamarin
Who is the Intended Audience for Xamarin?
The target audience for Xamarin can be divided into three groups:
- Android developers
- iOS developers
- .NET developers
The first two are obvious – Xamarin allows these developers to create apps for Android and iOS.
But, the third group is probably the reason that Microsoft finally acquired Xamarin. There are armies of .NET developers out there creating desktop and server apps for enterprises and consumers. Xamarin allows these developers to leverage their existing C# and .NET Framework skills to create apps for mobile.
One might argue that there is a fourth group that is also in the target audience: full-stack developers. A full-stack developer is one who is comfortable with both front-end and back-end technologies, mobile and server.
For simplicity’s sake, let’s just say that full-stack developers are included as part of 1, 2, and 3. And for the sake of accuracy, I must include Windows Phone developers in this group. Xamarin can be used to develop Windows Phone apps. But let’s be honest, the platform has less than 1% of the market share in 2016.
Why Should I Care about Xamarin?
Prior to the introduction of Xamarin, the choices for developing mobile apps were fairly limited and usually mutually exclusive.
For example, if you wanted to develop an iOS app, you were required to use Xcode and Objective-C. Furthermore, you had to use a Mac since Xcode only runs on a Mac.
If you wanted the same app to run on Android, you had to rewrite it using Android Studio and Java.
In short, there was no way to share code across the two major platforms. The result was that most apps were usually developed serially: iOS first, followed by Android if the iOS app generated enough interest.
Xamarin changes this equation in a couple of key ways.
First, both iOS and Android apps can be developed using the same tools and language. Second, since Xamarin uses C# as its programming language, code can be shared between both apps, saving a lot of time and effort.
As the graphic below from iCircuit indicates, developers can achieve 70% to nearly 100% code reuse between platforms!
What are the Costs Associated with Xamarin?
Prior to the acquisition by Microsoft, Xamarin was sold using a Software-as-a-Service (SaaS) model.
The subscription was divided into three groups of licenses:
- Starter (FREE)
- Indie ($25/month)
- Business ($999/year)
The Starter license was for developers or students who intended to use Xamarin to create apps for their personal use (i.e. not for making money). The Indie license was aimed at individual developers who intended to sell the apps they created using Xamarin.
And finally, the Business license was for enterprises that had several developers who intended to use Xamarin to create apps for both internal and commercial purposes. It was expensive and usually reserved for companies or departments with 10 or more developers.
All of this changed when Microsoft acquired Xamarin. According to the Xamarin blog, “Xamarin will be in every edition of Visual Studio, including the widely-available Visual Studio Community Edition, which is free for individual developers, open source projects, academic research, education, and small professional teams.”
The word “free” in the previous sentence is tempting, but should really have a huge asterisk next to it. Xamarin is free if you are:
- A student
- Doing Open Source Software (OSS) development
- A member of a small team (according to Microsoft’s definition of a small team)
Otherwise, Xamarin is not free; but the costs are lower and tied to your Visual Studio license. That’s right; Xamarin development can be done via Visual Studio!
So if you’re using Visual Studio for other C#/.NET development, you can start developing Xamarin apps today! More details on this complicated pricing structure can be found at the Xamarin store.
When and Where Can I Get Training for Xamarin?
Learning Xamarin is a multi-pronged approach, depending on your background. If you’re a seasoned C# developer, you will want to focus on the Xamarin.iOS and Xamarin.Android frameworks that allow apps to run on each of the major mobile platforms.
If you’re already familiar with the iOS and Android frameworks, but new to C# and .NET, you’ll want to spend some time understanding the syntax and .NET run-times available in Xamarin.
The good news is that the makers of Xamarin have made this very easy to do with something aptly named Xamarin University. All classes for Xamarin University are held on-line; but are otherwise just like a regular class.
Attendance is taken, pop quizzes are given randomly, and each class has labs that illustrate Xamarin topics with working code. Each class is roughly three hours in duration and the schedule is posted on the website to accommodate your time zone and busy work demands.
While not the focus of Xamarin University, certification is a nice fringe benefit of taking these classes. After taking approximately 20 classes, students can take an exam to certify their competence in Xamarin. The exam is comprehensive and takes about three hours to complete.
A score of 80% or higher earns you membership in the exclusive Xamarin Certified Mobile Developer club. At the time of the writing of this blog, there were less than 1,000 such developers, including your esteemed author.
The certification is good for one year and can be renewed by taking refresher courses. Finally, the price of Xamarin University is not cheap ($1,995 per year); but given the exclusivity, well worth the expense if you want to stand out in a crowded field of other developers.
How do I get started using Xamarin?
While Xamarin University is a great way to learn the platform in a formal setting, the cost is a bit high if you’re just looking to try it out. Xamarin does offer a 30-day free trial if you want to take a few courses before spending $2K. You can also download the free version of Xamarin Studio or Visual Studio Community Version and run a number of sample apps provided on Xamarin.com.
Here’s an Example Using Xamarin
But to illustrate how easy it is to write a simple Xamarin app, I’ve included a traditional “Hello World” sample below for Android.
What’s New in Xamarin?
Developers are strange beings. Sometimes the most banal topic can generate a heated debate. For example, ask a group of developers, which is preferred: tabs or spaces? (Tabs are good; spaces are evil, by the way)
Xamarin developers are not immune to this kind of religious fervor and the use of a new concept called Xamarin.Forms usually provoke such debates. Most of the non-common code in a Xamarin app comes from the user interface or hardware-specific portions of the code.
The Xamarin.iOS and Xamarin.Android targets wrap these platform-specific frameworks. Xamarin.Forms take all of the common controls and hardware features of both platforms and provide them in a single framework.
A button, for example, can be displayed in Xamarin.Forms and will look appropriate on both iOS and Android. Accessing the camera or GPS can likewise be abstracted in a Xamarin.Forms app.
So you might be asking yourself: “What’s the problem?”
In order to provide a common experience across BOTH platforms, Xamarin.Forms must use the least common denominator available on BOTH platforms. That means if there is some cool new feature available ONLY on Android, Xamarin.Forms can’t use it.
This restriction necessarily limits the types of apps that could be written using Xamarin.Forms. However, the line separating Forms from “native” Xamarin apps is blurred at best, hence the religious fervor. The diagram below attempts to put some rigor back into the argument.
Bringing it All Together
Hopefully, you now have a firm grasp on what Xamarin is, why it is gaining traction in the market, how much it costs, where to get training, and how to get started down the path to becoming a certified mobile developer.
My colleagues at Centric Consulting have authored another blog showing how they used Xamarin to develop a cross-platform employee engagement app, called Connect. Check it out as it offers a deeper look in the world of Xamarin!