I think we can all agree that developing mobile apps is a hot topic these days. One of the concerns I hear most often is having to deal with multiple languages, frameworks, and platforms. Everyone understandably wants to have a common toolset, write code once and reuse it as much code as they can, etc.
There are several ways to achieve this. One way is to forget native apps completely and just have a responsive website. Going this route will cost you a few things such as native device functionality (GPS, camera, accelerometer, etc.) and monetization (marketplace / app store presence).
What I want to look at in this post is Mono for Android, or MonoDroid, from Xamarin. There’s also MonoTouch for creating iOS apps, but that’ll be for later. These offerings allow developers to apply their existing C# and .NET skills to these platforms and share the code between them! The Mono for Android offering also provides the choice of using MonoDevelop or Visual Studio.
This is so simple, there’s not a whole lot to say. Head over to the trial download page, answer a few questions, and get the bits.
When the download completes, setup.exe will take care of everything for you. Relax as it discovers, downloads, and installs all the dependencies and configures them for you. Days before I got this, I manually got the Android SDK and got the emulator running for other reasons. This installer would have done all that for me, and it does more. Look at all these AVDs! The bottom one is the only one I had made myself.
When it’s all done, you can launch MonoDevelop or open Visual Studio (integration via a plugin).
Looking at MonoDevelop
I’m choosing to go the MonoDevelop route in this post for two reasons. First, I haven’t used MonoDevelop before and I figure I should see what all the good buzz is about. Second, some readers just might not have Visual Studio, but everyone who has come this far will have MonoDevelop. If you want a complete getting started guide for Visual Studio, you could check out Xamarin’s documentation. Alternatively, if someone asks me specifically to post about it, I will.
When you open MonoDevelop, you get a Start Page. The concept should be pretty familiar. Go ahead and start a new solution.
You can choose from a variety of Mono for Android project templates. Let’s go for the gold and target API 15 or higher (“Ice Cream Sandwich”).
The project should be created with a structure like this.
I’ll go into the details of what makes up the project in my next post. For tonight, let’s just hit F5 and confirm that we’ve got everything in place. When you hit F5, you’ll need to start an emulator. Since we’re using an Ice Cream Sandwich (API Level 15+), start that virtual device and then click OK.
Note: When I installed, I already had an AVD targeting 4.0.3 (API Level 15) and it was named Droid. You can see it hanging out in an earlier screenshot. I think the Mono for Android installer saw this and skipped creating MonoForAndroid_API_15 for me. I deleted Droid and created it in hopes of making this screenshot consistent. After I get a chance to confirm this on a clean install, I’ll update the post if necessary. In the meantime, if you don’t see a Level 15, go to Start >> AVD Manager and create one (it’s easy!)
The emulator will launch, and you can watch the installation progress in MonoDevelop.
Heads up: I’ve worked with four different AVDs on two different machines (with and without Mono). Android Virtual Devices take a long time the first time. It will get better.
Once it’s all complete, the sample click-counter app will be running in your emulator.
If you click the back button, the app will close, but you can still find it in the app list. I called my project IceCream, and you’ll see IceCream in the lower left of the list. Your name may vary
It’s oddly satisfying to see apps written in C# with .NET get deployed and executed on Android, and I’m pretty excited about diving in deeper and seeing how far we can take it. Next time, we’ll take a closer look at what all these files are and the concepts they represent.