Tuesday, February 21, 2012

Mono for Android Pros & Cons

Updated 5/4/2013

Recently, I had the opportunity to develop a project using Mono for Android. For those of you who are unfamiliar with Mono for Android, it enables you to develop Android apps using a .NET language like C# instead of Java. Overall, I've had a good experience using Mono for Android and I'm happy with the results. I've created a handful of apps using Mono for Android and they've all been successful.

The Mono for Android API closely mirrors the standard Android API. For example, nearly all of the same classes, methods, and fields are present in both APIs. One of the main differences is that Mono for Android utilizes properties and delegates which are non-existent in Java. I liked how closely the two APIs were related since this made it easy to switch back and forth between them and to use the wealth of documentation that already exists for the standard Android API.

Below is a list of pros and cons regarding Mono for Android:

PROS

  1. Share Code Between Platforms - If used in conjunction with the Mono Touch API and the Windows Phone API you can potentially reuse your business logic code for both the iPhone and Windows Phone platforms. This is possible since everything can be coded using a single, common programming language instead of 3 different programming languages. Please note that this only applies to business logic code though; presentation specific code will be different for each platform because of differences in the APIs. In my mind the ability to reuse code is the single greatest benefit in using Mono for Android.

  2. Use Your Existing .NET Skills - If you or the majority of your team members are knowledgeable with a .NET language but not with Java then using Mono for Android may be appropriate. However, I think this advantage is somewhat diminished by the fact that C# and Java are so similar. There is probably a greater benefit in using Mono Touch since this eliminates the need to learn Objective C which poses much more of a learning curve than Java.

  3. The C# Language - In my own opinion, the C# language has several advantages over Java (comparing only the core language and not other aspects such as frameworks, community, etc). LINQ, lamdas, and delegates are some of the features I love most about C#. These features aren't irreplaceable but they save time and effort. Perhaps Java's position will improve when version 8 is finally released.

CONS

  1. 3rd Party Android Libraries - In general it's more difficult (but not impossible) to use 3rd parties libraries with Mono for Android. Since most Android libraries are written in Java they must either be rewritten in C# or invoked with JNI. Mono for Android version 4.2+ includes a Binding project that can automatically wrap Java code in a JNI wrapper. The Binding tooling automates much of an otherwise difficult process. However, there is still a learning curve and manual adjustments are often necessary.

  2. Bugs - There is a significant amount of bugs in Mono for Android. Well, perhaps significant is too strong a word, but it is definitely more stable to use Java vs. Mono for Android. Two of the most serious bugs I encountered are: DateTime.Now returns time in the wrong time-zone (UTC), and using a SSL connection with WebClient causes an exception. (I believe these bugs are fixed now). Here is a full list of outstanding bugs.

  3. Debugging - Using the Mono for Android debugger can be a frustrating experience. It sometimes causes your app to crash or skips breakpoints for unknown reasons. Usually I resort to logging and avoid the debugger altogether. Xamarin has tried to fix the debugger but the problem has persisted for over a year now.

  4. Other Limitations - A list of other limitations is available here.

Personally, I'd lean more towards using Java and the standard Android API rather than using C# and the Mono for Android API. I say this because, first, I have a strong background in Java, and, second, using Java will likely result in less complications and limitations. However the ability to share the same code between Android, iPhone, and Windows Phone is very tempting and may be a deciding factor in some cases. At my current job I am part of a team of Microsoft developers, so using Mono for Android is typically the preferred method for creating apps within that environment.

Below is the Mono for Android website:

http://xamarin.com/monoforandroid

1 comment:

  1. Thanks that was informative. I've been playing with mono for android for the past few days trying to port a few .NET apps to android before purchasing it. I still think I should port the projects to java instead.

    ReplyDelete