Forum Cross Platform with Xamarin


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Migrating to Xamarin

ColinEberhardtColinEberhardt GBMember, Insider
edited October 2012 in Cross Platform with Xamarin

Hi Guys,

I've been talking with a few potential clients about the possibility of using Xamarin as an alternative to HTML5 for cross-platform development. I have met with teams who already have Android and iPhone versions of the same application, where I believe a cross platform solution using Xamarin would be quite beneficial.

If they wish to use Xamarin, do they have to port their entire codebase in one go? or is there the option to port some common logic first, then supply ObjC and Java bindings in order to use it in their existing applications? A gradual migration path would be a more palatable option - rather than a big-bang re-write!

Has anyone done a gradual migration from Android / iPhone native to a common Xamarin / C# codebase before?

Thanks, Colin E.


  • JonathanPeppersJonathanPeppers USInsider, Beta, University ✭✭
    edited October 2012

    I have worked with a client that did this with a large iOS application, and it seemed to work pretty well.

    They basically rewrote the core startup of the app in C# with MonoTouch, then moved all their Objective-C controllers and code to a reusable library and setup a MonoTouch binding project for that library. You should also be able to completely reused any XIB or Storyboard files you have, also. Just keep in mind, depending on how complex each controller is, it might be just as much work to rewrite some controllers in C# as it would be to write the binding.

    The same technique should work in Mono for Android as well, here is an article briefly talking about it:

  • decriptordecriptor USBeta, Developer Group Leader Xamurai

    We did that with our monotouch app and have been slowly porting it over. When we started our android app we were already using the xamarin tools.

    As JonathanPeppers mentioned with the xib files, android xml files should be the same.

  • decriptordecriptor USBeta, Developer Group Leader Xamurai

    Thinking about it, an android port from java to c# will definitely present some issues, but I don't know that it'll be that horrible. I've found several examples in java on the internet and converted them to c# for different things. A couple things that comes to mind are anonymous classes and 'applying c# style' things like properties instead of get/set in many cases.

    One of the things that I love is that xamarin auto updates the manifest file so you don't have to worry as much about activities, services, and permissions.

  • ColinEberhardtColinEberhardt GBMember, Insider

    Thanks both of you. For some reason I had it in my head that you would have to write an ObjC binding for the shared C# code which had initially been ported - and was pretty sure that this would not work.

    Creating a C# binding for the parts that you do not want to initially port, and using them from a new MonoTouch app makes sense to me. Thanks for the ideas.

  • NicWiseNicWise NZMember, Insider, Beta mod

    If their app is HTML5, then they would have to rewrite it - you can't use C# from in a HTML5 hybrid app (AFAIK) (well, you could, but you'd be recreating PhoneGap/Appcelerator in MonoTouch/MfA....)

    But if it's Java or ObjC, then yeah - package it up as a native lib and use it, and gradually migrate the core, non-visual stuff away.

    It may not be economically viable, but you would get a better long term result out of a full rewrite, using the existing code as a reference point.

    You can then work out the best architecture for the common code, and reuse a lot of the UI stuff you already have (by just doing a 1:1 code port)

    I'm doing that with an ObjC iOS app, porting it to Android, and after that, iOS. I got to rethink how the networking, database storage etc all worked (someone else wrote the original ObjC version), so this version has offline access, background uploads, a lot of off-thread async stuff etc, which the original didn't have.

  • ColinEberhardtColinEberhardt GBMember, Insider

    The code is native, Android and iOS.

    To your point on isn't C# code in a HTML5 app, you would not be reinventing Titanium, rather re-inventing something like PhoneGap, which is not such a big job. Anyhow, not a task I would want to take on!


  • StuartLodgeStuartLodge USBeta ✭✭✭

    Not really an answer to this question... but Colin - have you seen the port that Xamarin did of the whole of Android to C# - - there's some stuff in there (Sharpen?) that might help with the bulk of the Android porting

  • kalaiselvankalaiselvan USMember ✭✭

    @ColinEberhardt I've come across the same use-case, and decided to port Cordova in to Xamarin(for Android).
    I've tried Jar/AAR binding method, extended CordovaActivity to a Mono Activity but couldnt even start the app, exception cannot cast Mono Activity to Android Activity.
    So decided to re-write in C#. Here's the link for a crude port. I did manage to get it working on Android.

    I wanted to merge it with WinPhone8.1 libraray (you know using renderers and all, a proper forms library, so that plugins can be developed easily), but there seems to be an awful lot of differences between them.

Sign In or Register to comment.