Mono for Android Tips
I’m currently working on an Android shopping application for my employer that is built in .NET using Mono for Android by Xamarin. You don’t need to click any of those links, they’re just for reference
This is a collection of random hints, tips, observations that I have encountered while working on this project. If you’re wondering whether to use Mono in your project some of these comments may give you an idea what it’s like to work in Mono for Android.
- Developing in Mono is almost exactly like developing in Java. In fact, almost every tutorial that I’ve found in Java can be directly converted to C# with minor syntax differences. This is a huge plus because it means that I get the power and familiarity of the C# syntax and the Visual Studio environment but almost all of the tutorials and references I find are applicable.
- One of the exceptions to the above is, for the most part, the AndroidManifest.xml document is abstracted away in Mono. Instead, it uses attributes on your activity classes and generates the XML at compile time. I have mixed feelings about this. It’s very nice in some respects because the attributes are easily-visible while you’re working on an Activity. On the other hand, if you’re reading Android documentation about Intent Filters and other attributes that govern interaction between activities and the Android OS…it can be hard to translate those into attributes correctly. I think you can still edit the AndroidManifest.xml file but I’m not sure how Mono merges the generated and custom XML. In my opinion, this part of Mono has huge potential for leaky abstraction.
- You still use exactly the same UI XML in Mono. Unfortunately the Intellisense doesn’t work correctly on the XML documents so it’s easy to mistype or get property names wrong unless you have them all memorized (I don’t). Add to that that the Android UI attributes are convoluted and complex (like learning a new version of HTML + CSS) and UI design via XML is a giant, sucky time sink. But the Google team has created a WONDERFUL (bold, capitalized and italic!) WYSIWYG UI designer. I generally hate WYSIWYGs because they generate crappy code and have lots of bugs. This one completely avoids those traps and spits out beautiful XML that makes unicorns dance along shining rainbows.
Unfortunately it plugs into Eclipse. I ended up created an Android project in Eclipse just to use the WYSIWYG for UI design. Then I just copy/paste the XML files from the Eclipse project into my Mono project. Despite how kludgy that sounds, this has improved my efficiency at UI development by about 1000%. I cannot stress how critical it is to use this UI designer as it will save you tons of time and headaches.
- My company hoped that using Mono would make it easier to develop iOS and Android applications simultaneously. This concept was both true and false. We hoped that we would be able to share a lot of the back end logic between projects and just wire up the UI separately for each platform. While this probably could be accomplished it hasn’t proved feasible for us. It’s actually easier for us to keep the projects separate and just share ideas on similar parts. Completely decoupling native platform objects from code added a layer of complexity and maintenance that we didn’t feel would save us any time in the short or long run. That being said, using Mono does make it easier for us to examine each others’ code and see exactly what’s going on. Overall I would say this was a win despite it not working quite how we thought.
- Mono is stable. I’m a version behind and I have some issues with a really slow debugger (I think this is fixed or improved in the latest version) but otherwise I never have problems with the Mono platform. In fact, the UI response feels really snappy on the Motorola Droid that I’m using as the main dev phone.
Those are the main things I can think of right now. However, bookmark this post as I will probably add things as I encounter or remember them If you have questions, hit me up in the comments and I’ll answer them the best I can!
One other thing, we’re releasing the Sierra Trading Post API on Mashery very shortly. This is near-identical to the API I’m consuming to power our official app. Unlike many APIs, ours supports the use of your affiliate account to earn revenue from purchases made through API-provided links. This is potentially more lucrative than ads! So, if you’re an android dev check out our API…we may be offering special prizes or incentives for creative, quality implementations. Note that we’re just launching so bear with us as we flesh out the docs and open up the program!