48

This question is specifically related to a recommended architecture and people's previous experiences for cross-platform WP7, iOS, Android apps developed using C#, Monotouch and Monodroid respectively. I have researched previous questions here, here and here. They provide good answers but not quite what I'm looking for. I have also found this excellent question which does go into the cost benefit so there is some overlap.

I have a requirement to develop a cross-platform iPhone/iPad, WP7 and android app for a health & fitness company, which will integrate with their website. The app requires a small amount of local data storage for offline mode and synchronisation with the website when a network is available. I am a Windows (C#/C++) developer through and through and don't really want to go down the route of three Objective C, Java and C# apps, although I will if I have to. I will also be operating as tech lead and farming out some work to a team on this project.

I would like to know if anyone here has experience with cross-platform development using Monotouch, Monodroid and WP7 and to share their experience on application architecture to re-use as much code as possible. The architecture I am considering is as follows:

Proposed architecture for Wp7, Monotouch, Monodroid app

My question is as follows:

  • Has anyone here tried something like this?
  • Are these frameworks (Monotouch, monodroid) worth their salt for this sort of work?
  • Can I setup the entire project in Visual Studio 2010 with separate projects (dlls/exe) for the Monotouch, Monodroid and Wp7 target (but shared code using 'Add as Link')?
  • What sort of code-reuse can I realistically expect with this (or a similar) architecture? i.e. what strategies/patterns can I use to re-use local data access, webservices, and business logic?
Anton Menshov
  • 2,266
  • 14
  • 34
  • 55
Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178
  • 44
    I like your cloud drawing – Steve B Jan 06 '12 at 09:36
  • Thanks, its trademarked don't you know ;-) The Cloud that is, not the drawing – Dr. Andrew Burnett-Thompson Jan 06 '12 at 09:38
  • 1
    If you are acting as the architect, doesn't it make more sense to take an approach that is not constrained by your own technical expertise (C# / C++)? As indicated by the questions you reference HTML / PhoneGap / JavaScript is a tried and tested approach for solving this issue. It is of course not without pitfalls and the ride is not easy, but it certainly can and has been done. I am interested in the answers you may receive none-the-less. – ColinE Jan 06 '12 at 09:46
  • 1
    How complex is the business logic? I bet you are better off writing native apps without mono wrappers. – Lukasz Madon Jan 06 '12 at 09:57
  • Hi colin, yes you are right - that would be a wise choice, but could a solution like this work in offline mode? Remember its also an app not a website, so the client wants to deliver the content through the appstores and charge for it - can HTML5/Js fit the above requirements? BTW feel free to put answers, even if they're short as I can mark them up. Regards, – Dr. Andrew Burnett-Thompson Jan 06 '12 at 09:57
  • 1
    PhoneGap claims "PhoneGap is an HTML5 app platform that allows you to author native applications with web technologies and get access to APIs and app stores" so seems you can charge for the app. – Lukasz Madon Jan 06 '12 at 10:06
  • @lukas, thank you. Isn't HTML5 dog slow on iphone? I heard that WP7 whoops it in terms of performance. Business logic is not that complex, but one rationale of having a single solution to build all three is to ensure all three get updated in sync – Dr. Andrew Burnett-Thompson Jan 06 '12 at 10:16
  • 1
    wp7 7.5 aka "Mango" has got IE9 web browser which is hardware accelerated - it leverages GPU for various scenarios. On the other hand, iPhone has more powerful hardware. The question is: Will your app suffer from the performance? – Lukasz Madon Jan 06 '12 at 10:21
  • @lukas, Yes basically. Performance is a consideration. I feel a feasibility study coming on :) – Dr. Andrew Burnett-Thompson Jan 06 '12 at 10:27
  • 4
    The best example of sharing code between a MonoTouch application, a Mono for Android application and Windows Phone 7 application I have found is from Jonas - jonas.follesoe.no/2011/07/22/cross-platform-mobile-ndc-2011/ so that might be worth a watch. – chrisntr Jan 06 '12 at 12:46
  • @chrisntr thank you - all help appreciated :) – Dr. Andrew Burnett-Thompson Jan 06 '12 at 12:49
  • 3
    I'm working on an app with one unified codebase powering windows, android, and wp7 apps, ios/OSX coming soon. All powered by mono, so far so good. To all you "for performance go native" folks - well you're wrong. I am a native android developer and mono blazes on ios and android. Can't say that about the html frameworks. The reason I chose mono instead of native for this particular platform is to avoid a fragmented codebase and the need to deal with 3 separate sets of bugs. Totally happy with my choice. – tempy Jan 06 '12 at 17:30
  • @tempy would be interested to talk about your dev setup, would you mind emailing me? Twitter/mail on my profile. Best Regards – Dr. Andrew Burnett-Thompson Jan 06 '12 at 17:32
  • Take a look at this post http://stackoverflow.com/a/5405751/485076 – sll Jan 16 '12 at 16:43

4 Answers4

25

You might want to look into the MonoCross project which is designed to help you reuse C# code with multiple presentation layers:

http://code.google.com/p/monocross/

The authors of MonoCross (ITR Mobility) have created multiple mobile cross platform solutions for a variety of customers and have written two books on the subject one is "iPad in the Enterprise" (http://amzn.to/zAhQK6) and the upcoming "Cross-Platform Mobile Development with C#" (http://amzn.to/wM6RsF).

In the meantime, you can watch Scott Olson's presentation that he did at Monospace 2011 that describes how to use MonoCross to target multiple mobile and desktop platforms at once reusing the business logic:

http://www.infoq.com/presentations/The-Rise-of-Mono-in-the-Enterprise

They enforce a strict MVC split in their code:

MonoCross MVC Pattern
(source: tirania.org)

The biggest benefit of designing an application with this model is that you can run the same application with native user interfaces on each platform. You get native iOS, Android, Windows UI and they even have an ASP.NET front-end that allows you to publish Web versions of the same business logic.

This technology was used successfully by the Medtronic sample app that is showcased by Apple in their iPad business:

http://www.apple.com/ipad/business/profiles/medtronic/

I suggest you also check out Scott's blog where he posts regularly about his experiences with cross-platform architecture.

Community
  • 1
  • 1
miguel.de.icaza
  • 32,654
  • 6
  • 58
  • 76
  • Oh yes. Looks like my kinda framework (full on mnet). Thanks for sharing, appreciate the info. – Dr. Andrew Burnett-Thompson Jan 08 '12 at 20:31
  • In fact, Im half tempted to unmark the HTML5 answer and mark this as answer ;) Sorry Colin. Going to do some feasibility on both but I do prefer the idea of a full .NET solution. Tell me does the abvoe also work on Windows Phone? (You mention Windows UI I assumed that meand windows desktop). We wish to publish a WP7, Android, iPhone, iPad as well as ASP.NET (website) version of the same app. – Dr. Andrew Burnett-Thompson Jan 16 '12 at 09:46
  • 1
    Yes, the above works with Windows Phone 7. We have also been adding a cross-platform API for common services: http://blog.xamarin.com/2011/11/22/introducing-the-xamarin-mobile-api/ – miguel.de.icaza Jan 16 '12 at 14:18
9

Just adding another alternative to the mix - mvvmcross

This project was developed out of experiences with monocross, mvvmlight, and opennetcf.

It's quite an opinionated mvvm framework (with my opinions in it!), it includes data-binding support for Droid and Touch, and it really does encourage code reuse between the platforms.

The source is available from https://github.com/slodge/MvvmCross, it's been used in at least a couple of large projects already and it's still under active development.

There's an introductory presentation on it on slideshare: http://www.slideshare.net/cirrious/dev-evening-monotouch-monodroid-mvvm-mvvmcross-and-databinding

One of the more fully featured samples is a conference app:

sql bits app

Stuart
  • 66,722
  • 7
  • 114
  • 165
9

Based on your comments your requirements are for a cross-mobile platform that will integrate with their existing services, but also work offline. You are specifically interested in C# via Mono, however you have indicated that you are not discounting other approaches.

I feel that HTML / PhoneGap / JavaScript is a route that you should explore in some detail. The WP7 version of this framework has just been released, and I have had experience of releasing an application to the marketplace using this approach.

PhoneGap wraps your HTML / JavaScript code, in the case of WP7 this is loaded into local storage. This enables the application to work entirely offline. This is true for all versions (iOS, Android etc...)

Probably the biggest issue with PhoneGap / HTML5 is the same issue we have when developing complex web based applications for the browser. The tooling for JavaScript is not great and browser differences are a constant issue. However, it is a tried and tested solution.

Finally, it is possible to create an application UI that is entirely different for each platform. By using the MVVM pattern I have managed to share all my JavaScript business logic between WP7 and iOS applications whilst having a totally different UI:

enter image description here

Compare this to the WP7 screens:

enter image description here

NOTE: I plan to have the iOS version of Property Finder in the AppStore shortly, I just need to work out how to use PhoneGap Build!

ColinE
  • 68,894
  • 15
  • 164
  • 232
  • I'm really impressed with this thanks. Can you comment on performance experiences on iphone/ipad/wp7/android using PhoneGap/HTML5? I've heard on the grapevine that ios is dog slow when rendering HTML content. – Dr. Andrew Burnett-Thompson Jan 06 '12 at 10:22
  • 2
    The situation is quite the opposite, the webkit browser used in iOS is very fast (for a mobile browser), with good CSS3 support and hardware acceleration. A while back I created a HTML5 jump list control. The performance on a cheap iPod Touch was better than the WP7 Silverlight version I have written! http://www.codeproject.com/KB/scripting/SilverlightToHTML5.aspx – ColinE Jan 06 '12 at 10:25
  • gah, ok you've convinced me (even though I hate javascript). I'll be following your tutorial after a my holiday next week :) Regarding camera, can I still access this? Its a small feature but I just remebered the client wants users to take before/after pictures of themselves whilst using the app. I suppose an upload button could be incorporated to select a file from local disk. – Dr. Andrew Burnett-Thompson Jan 06 '12 at 10:39
  • second question, MVVM in HTML5/JS? :o – Dr. Andrew Burnett-Thompson Jan 06 '12 at 10:42
  • 2
    Camera, yes, PhoneGap has an API for that. MVVM, sure - I use KnockoutJS,, a rather neat framework. I used to hate JavaScript, but have learnt that if you do it properly, you can create some great results. You just have to understand that JavaScript has some pretty major flaws (see this excellent article http://www.codeproject.com/KB/scripting/javascript-gotchas.aspx) and learn to work around them. – ColinE Jan 06 '12 at 11:36
  • thanks again. Very informative and influencing the direction of this project. Glad I asked - btw want my job? Joke joke – Dr. Andrew Burnett-Thompson Jan 06 '12 at 12:04
  • I've done phonegap and mono *xamarin and because of the lack of multithreading on phonegap's part I prefer Xamarin. – yams May 09 '16 at 18:53
1

The question is very hard to answer, yet I would like to share some thoughts.

The situation with the mobile development is very similar to the development at the first half of the 90s. Phone have limited resources as computers had, mobile OSes are making their baby steps, hence the ecosystem is relatively small. They have own philosophy, tools and even languages. And this is a good thing, but leads to a headache for cross-platform development. As a result, there are many attempts to clear this a bit. People build frameworks, wrappers etc. which is a kind of abstraction and abstractions are leaky. This is extremely important for mobile devices not only the performance as numbers of CPU cycles, but also the performance of the battery, which is far more important for the user.

If I were you I would build apps in a native environment especially if you have some performance considerations. Best support, tools, educational resources etc. pays for the duplicated business logic. All in all, it's not a OS or Database Management System, codebase won't be huge ;)

That being said. Regarding Monotouch and Monodroid I would be very careful since Apple blocks iPhone OS apps created by many third-party compilers and The King doesn't really care about developers. The case that mono will be flushed to the toiled by patent infringement or proprietary software vendors is very likely. This is sad for me cause C# is my favorite language.

PS. I don't believe that HTML5 for mobile will take over any time soon.

Community
  • 1
  • 1
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108
  • A good general answer, however I just want to point out a problem with your statement "Apple blocks iPhone OS apps created by many third-party compilers", this article is out-dated. Apple have changed their stance on this in the past year. You can find numerous PhoneGap (HTML5) apps, Titanium (proprietary cross-platform), AppMobi, and Mobile AIR (Adobe Flash / Flex) apps on the Apple AppStore. Times are a-changing! – ColinE Jan 06 '12 at 11:42
  • @lukas thanks for the informative answer. I havent made a decision as yet but Colin's answer gave me something to think about. I agree with your statement about phone maturity and that native support in each OS may be a benefit over "one hacky framework to rule them all" (TM). My only concern about splitting to three codebases is keeping them updated in sync. With a small dev team we're going to be stretched to do this as it is. With 3x apps to maintain it could be impossible. Ahh! If only the days of Windows-only dev were still here :) – Dr. Andrew Burnett-Thompson Jan 06 '12 at 12:07
  • @Lukas dont know who marked your question down but I personally found it very helpful. – Dr. Andrew Burnett-Thompson Jan 06 '12 at 12:52
  • 2
    Downvoting for a very out-of-date and unnecessarily flame-baity answer. If you have specific patent concerns, please state them. Also, apple's stance toward 3rd party development frameworks has long ago been elucidated during the 3.3.1 controversy that has come and gone, see: http://tirania.org/blog/archive/2010/Sep-09.html – tempy Jan 06 '12 at 17:28
  • @tempy I am aware that Apple let MonoTouch apps in appstore. My concern is that they could done it again if they see a threat. Similar to whole mono project, C# is open, but .Net is not. I don't have specific patent concerns yet Apple, MS, Google will defend their products against f.e. patent trolls, not sure about Mono. – Lukasz Madon Jan 06 '12 at 18:19