Advantages and disadvantages of Xamarin
- Transfer
Hi, Habr! Today we will tell you about what users like in Xamarin, our tool for cross-platform development of mobile applications. In addition, we will touch on the disadvantages of the platform. By the way, under the cut you will find a lot of code and good examples, not just the text with the listing. Join now!

The article was prepared by our partners, the guys from EGO.
Xamarin is a handy toolkit for developing cross-platform mobile applications in C # using .NET. It supports iOS, Android and Windows Phone.
To develop an application based on Xamarin, you do not need to thoroughly know the specific languages of individual platforms. In addition, when working with any platform, you will have full access to the capabilities of its SDK package and built-in mechanisms for creating user interfaces.
Thus, Xamarin allows you to create applications that are almost no different from native analogs, which means that they are quite suitable for distribution through official stores (for example, Google Play and the App Store).
In addition, according to the developers of Xamarin, a ready-made solution will not be significantly inferior in terms of performance.
Consider the component parts of Xamarin.
This article describes seven significant reasons for using Xamarin for cross-platform development.

Additional materials: comparison of Xamarin and PhoneGap .
What should be the first thing to pay attention to when choosing a platform? Of course, on the complexity of its development. It is unlikely that there are many willing to spend time on mastering the features of the syntax (for example, for a sufficiently confident possession of Angular it is required to study this platform for at least several months). Therefore, if the creation of high-quality code requires extremely serious preparation, many newcomers simply cannot fully master the development environment. But getting started with Xamarin is completely simple: you don’t have to learn Xamarin or anything like that.
It is enough to know the C # language with its imperative style of writing programs, to feel free in the .NET environment and to explore several classes related to specific platforms.
Source .
To create a completely native application for a given platform, you need to be proficient in the Java language (in the case of Android) or Objective-C / Swift (for iOS). In some cases, this can be a serious obstacle. Let's see how the same task, which involves creating an attribute string, is solved in Objective-C and in C #.
In Objective-C:
In C #:
If you do not use the cross-platform development capabilities of Xamarin, then to create a commercial project that would have sufficient performance on both platforms, you may need to use two different approaches at once. So, the costs almost doubled.
Based on the advantages described above, it can be noted that cross-platform development using Xamarin requires approximately 1.5 times less time (and money) than creating a separate specialized project for each platform.
Of course, some code fragments (for example, service components) will be the same in both versions, and some others (in particular, business logic that does not use specialized functions of the user device) will require only minor changes. However, the overall situation is a bit more complicated. Some components of your application will inevitably have to write from scratch for each OS. When creating and deploying two applications for two platforms, it is almost always necessary to hire two development teams. Using Xamarin is much easier:
thanks to platform-independent APIs, approximately 70% of the code will be written in a universal format.
In this example, the MainPage class uses the ITextToSpeech interface to select the desired function on a specific platform:
One of the main reasons why developers avoid cross-platform development tools is that such tools do not allow using the full range of capabilities of specific environments. This primarily relates to the design (Flat Design in iOS, Material Design in Android) and the intellectual capabilities of user devices (application access to contacts, camera, GPS data, etc.).
The final cross-platform solution will not have high performance (this drawback is inherent in almost all applications created using cross-platform web tools) and will not be able to take advantage of specific platforms (which means that some of the features originally planned by the project creator may not fully implemented).
However, things are different when using Xamarin tools for cross-platform development of native applications. In this case, you will not encounter the above problems. Developers have access not only to the standard .NET classes: they can easily connect and the classes supported by a specific mobile platform (they are contained in the C # libraries for Xamarin.Android and Xamarin.iOS, respectively). This means that when using Xamarin to develop applications for iOS and Android, you will have at your disposal the entire set of capabilities of these platforms. You do not need to use third-party (and usually paid) tools.
Testing a product that is being prepared for release is not a trivial task, especially when it comes to the Android platform. The screen formats of custom iOS devices are clearly defined and known in advance, but Android devices are very different. If an application has not been tested on a specific device, its interface may in some cases be “parted”. The creators of Xamarin have proposed a solution for this problem.
In particular, the Test Cloud environment is also available for users of the platform , which allows to emulate more than 2000 devices. This decision is not free, but the cost of it will be justified.

Additional materials: nine best testing tools for mobile applications for iOS and Android .
If you want your application to receive data about the user's location, gyro, accelerometer, or other embedded sensors, then Xamarin is an excellent choice.
This development environment is fully compatible with IoT devices (for example, with Estimote ), allowing you to receive location data, which means that you will not have to configure integration with third-party solutions (especially since there will be no such possibility in principle).
Well-organized documentation is available for Xamarin with practical examples, code snippets, and step-by-step instructions.
Of course, some questions cannot be answered in it. In this case, the online community will help you. There are two official Xamarin communities: on the official website of the platform and on the StackOverflow portal.
If here you were unable to obtain the information of interest (some developers complain that community experts are not very active), you can contact the private technical support service available to Xamarin business license holders. Experts will answer you within a few hours and offer not just a set of standard procedures that rarely help to completely eliminate the problem, but detailed step-by-step instructions on how to solve exactly your problem.
Almost every IT company has a developed infrastructure of software used on the Windows platform.
For all editions of Visual Studio (for Mac OS and Windows), Xamarin is also available from spring 2016 as part of the subscription. If you are already using Visual Studio for development, there will be no additional charge.
We tried to explain in detail about the strengths of Xamarin and considered a number of its obvious advantages. However, we would like to make this review more objective, so we turn to the weak points of the solution. In fact, only one drawback deserves attention: the size of applications written using Xamarin, usually slightly exceeds the amount of native analogues. Nevertheless, optimization is never superfluous.
Xamarin has a number of advantages and is well suited for large-scale projects for the development of cross-platform applications that are complex from an architectural point of view, similar to native solutions.

The article was prepared by our partners, the guys from EGO.
Xamarin is a handy toolkit for developing cross-platform mobile applications in C # using .NET. It supports iOS, Android and Windows Phone.
To develop an application based on Xamarin, you do not need to thoroughly know the specific languages of individual platforms. In addition, when working with any platform, you will have full access to the capabilities of its SDK package and built-in mechanisms for creating user interfaces.
Thus, Xamarin allows you to create applications that are almost no different from native analogs, which means that they are quite suitable for distribution through official stores (for example, Google Play and the App Store).
In addition, according to the developers of Xamarin, a ready-made solution will not be significantly inferior in terms of performance.
Consider the component parts of Xamarin.
- Xamarin.IOS is a C # class library that provides developers with access to the SDK for iOS.
- Xamarin.Android is a C # class library that provides developers with access to the Android SDK.
- C # compiler.
- .NET Framework.
- IDE tools (built into Visual Studio for Mac OS and Windows).
This article describes seven significant reasons for using Xamarin for cross-platform development.

Additional materials: comparison of Xamarin and PhoneGap .
1. Easy to learn
What should be the first thing to pay attention to when choosing a platform? Of course, on the complexity of its development. It is unlikely that there are many willing to spend time on mastering the features of the syntax (for example, for a sufficiently confident possession of Angular it is required to study this platform for at least several months). Therefore, if the creation of high-quality code requires extremely serious preparation, many newcomers simply cannot fully master the development environment. But getting started with Xamarin is completely simple: you don’t have to learn Xamarin or anything like that.
using Xamarin.Forms;
RootPage.Children.Add(new ContentPage
{
Content = new Label
{
Text = "Sketches in Forms",
BackgroundColor = Color.Yellow,
TextColor = Color.Blue,
Font = Font.SystemFontOfSize(NamedSize.Large),
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
}
});
It is enough to know the C # language with its imperative style of writing programs, to feel free in the .NET environment and to explore several classes related to specific platforms.
using System.Diagnostics;
using Foundation;
using UIKit;
namespaceNeonPlayerConcept.iOS
{
[Register("AppDelegate")]
publicclassAppDelegate : UIApplicationDelegate
{
publicoverride UIWindow Window { get; set; }
publicstaticvoidMain(string[] args)
{
UIApplication.Main(args, null, "AppDelegate");
}
}
}
Source .
To create a completely native application for a given platform, you need to be proficient in the Java language (in the case of Android) or Objective-C / Swift (for iOS). In some cases, this can be a serious obstacle. Let's see how the same task, which involves creating an attribute string, is solved in Objective-C and in C #.
In Objective-C:
CFStringRef stringKeys[] *
{
kCTFontAttributeName,
kCTForegroundColorAttributeName
};
CFTypeRef stringValues[] *
{
myListFontRef,
COColorGetConstantColor(kCOColorWhite)
};
attr = CFDictionaryCreate (kCGAllocatorDefault,
(constvoid **) &stringKeys,
(constvoid **) &stringValues,
sizeof(stringKeys) / sizeof(stringKeys[0]),
&kCFTypeDictionaryKeyCallbacks,
&kCFTypeDictionaryValueCallbacks);
astr = CFAttributedStringCreate(kCFAllocatorDefault, CFSTR(“Hello from ego team!”), attr);
In C #:
var stringAttributes = new CFStringAttributes
{
Font = myFont,
ForegroundColor = UIColor.White.CGColor
};
var myString = new NSAttributedString (“Hello from EGO team!”, attrs);
If you do not use the cross-platform development capabilities of Xamarin, then to create a commercial project that would have sufficient performance on both platforms, you may need to use two different approaches at once. So, the costs almost doubled.
2. Reducing project costs
Based on the advantages described above, it can be noted that cross-platform development using Xamarin requires approximately 1.5 times less time (and money) than creating a separate specialized project for each platform.
Of course, some code fragments (for example, service components) will be the same in both versions, and some others (in particular, business logic that does not use specialized functions of the user device) will require only minor changes. However, the overall situation is a bit more complicated. Some components of your application will inevitably have to write from scratch for each OS. When creating and deploying two applications for two platforms, it is almost always necessary to hire two development teams. Using Xamarin is much easier:
thanks to platform-independent APIs, approximately 70% of the code will be written in a universal format.
In this example, the MainPage class uses the ITextToSpeech interface to select the desired function on a specific platform:
ITextToSpeech.cs:
publicinterfaceITextToSpeech
{
voidSpeak (string text);
}
TextToSpeech_Android.cs:
[assembly: Dependency (typeof (TextToSpeech_Android))]
namespaceUsingDependencyService.Android
{
publicclassTextToSpeech_Android : Java.Lang.Object, ITextToSpeech
{
TextToSpeech speaker;
string toSpeak;
publicTextToSpeech_Android () {}
publicvoidSpeak (string text)
{
\\Android-specific code
}
}
}
TextToSpeech_iOS.cs:
[assembly: Dependency (typeof (TextToSpeech_iOS))]
namespaceUsingDependencyService.iOS
{
publicclassTextToSpeech_iOS : ITextToSpeech
{
TextToSpeech speaker;
string toSpeak;
publicTextToSpeech_Android () {}
publicvoidSpeak (string text)
{
… \\iOS-specific code
}
}
}
MainPage.cs:
publicclassMainPage : ContentPage
{
public MainPage []
{
var speak = new Button
{
Text = “Hello, world!”,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
speak.Clicked += (sender, e) =>
{
DependencyService.Get<ITextToSpeech>().Speak("Hello from Xamarin Forms");
};
Content = speak;
}
}
3. Ability to create user interfaces similar to "native"
One of the main reasons why developers avoid cross-platform development tools is that such tools do not allow using the full range of capabilities of specific environments. This primarily relates to the design (Flat Design in iOS, Material Design in Android) and the intellectual capabilities of user devices (application access to contacts, camera, GPS data, etc.).
The final cross-platform solution will not have high performance (this drawback is inherent in almost all applications created using cross-platform web tools) and will not be able to take advantage of specific platforms (which means that some of the features originally planned by the project creator may not fully implemented).
However, things are different when using Xamarin tools for cross-platform development of native applications. In this case, you will not encounter the above problems. Developers have access not only to the standard .NET classes: they can easily connect and the classes supported by a specific mobile platform (they are contained in the C # libraries for Xamarin.Android and Xamarin.iOS, respectively). This means that when using Xamarin to develop applications for iOS and Android, you will have at your disposal the entire set of capabilities of these platforms. You do not need to use third-party (and usually paid) tools.
4. Optimal conditions for testing
Testing a product that is being prepared for release is not a trivial task, especially when it comes to the Android platform. The screen formats of custom iOS devices are clearly defined and known in advance, but Android devices are very different. If an application has not been tested on a specific device, its interface may in some cases be “parted”. The creators of Xamarin have proposed a solution for this problem.
In particular, the Test Cloud environment is also available for users of the platform , which allows to emulate more than 2000 devices. This decision is not free, but the cost of it will be justified.

Additional materials: nine best testing tools for mobile applications for iOS and Android .
5. Perfect compatibility with Internet of Things devices
If you want your application to receive data about the user's location, gyro, accelerometer, or other embedded sensors, then Xamarin is an excellent choice.
privatevoidInstance_Ranged(object sender,
System.Collections.Generic.IEnumerable<IBeacon> e)
{
Try
{
var data = string.Empty;
foreach (var beacon in e)
{
data = $@”region id: {beacon}
}
_labelContent.Text = data;
LogStatus(@”Ranged”);
}
catch (Exception exception)
{
LogStatus(exception.ToString());
}
}
This development environment is fully compatible with IoT devices (for example, with Estimote ), allowing you to receive location data, which means that you will not have to configure integration with third-party solutions (especially since there will be no such possibility in principle).
6. Qualitative documentation and a large community
Well-organized documentation is available for Xamarin with practical examples, code snippets, and step-by-step instructions.
Of course, some questions cannot be answered in it. In this case, the online community will help you. There are two official Xamarin communities: on the official website of the platform and on the StackOverflow portal.
If here you were unable to obtain the information of interest (some developers complain that community experts are not very active), you can contact the private technical support service available to Xamarin business license holders. Experts will answer you within a few hours and offer not just a set of standard procedures that rarely help to completely eliminate the problem, but detailed step-by-step instructions on how to solve exactly your problem.
7. Flawless integration with Microsoft Windows
Almost every IT company has a developed infrastructure of software used on the Windows platform.
For all editions of Visual Studio (for Mac OS and Windows), Xamarin is also available from spring 2016 as part of the subscription. If you are already using Visual Studio for development, there will be no additional charge.
Disadvantages of Xamarin
We tried to explain in detail about the strengths of Xamarin and considered a number of its obvious advantages. However, we would like to make this review more objective, so we turn to the weak points of the solution. In fact, only one drawback deserves attention: the size of applications written using Xamarin, usually slightly exceeds the amount of native analogues. Nevertheless, optimization is never superfluous.
So how effective is Xamarin?
Xamarin has a number of advantages and is well suited for large-scale projects for the development of cross-platform applications that are complex from an architectural point of view, similar to native solutions.