MonoDroid 101–Installation and Hello World with Mono for Android

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).

Another, which I’ll be speaking about at CodeStock 2012 (and probably should have blogged about before), is PhoneGap. With this option, we leverage our standard web development toolset (HTML, JavaScript, CSS) and bridge the gap with some native libraries. Now we’re closer to a write-once scenario but we can still take advantage of the things we lost above.

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.

Installation (Windows)

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.

Download Mono For Android

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.

AVD Manager

When it’s all done, you can launch MonoDevelop or open Visual Studio (integration via a plugin).

You're Ready!

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.

MonoDevelop Start Page

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”).

project template choices

Hello MonoDroid

The project should be created with a structure like this.

project template

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.

AVD selection

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.

MonoDevelop deployment status

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.

application running in 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 Smile

emulator app list

Summary

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.

Advertisements

About David Ruttka

I've been "making computers do things" since I first saw King's Quest on a 286 PC in the mid-80's, but I turned it into a career just over a decade ago. While the majority of my experience has been on the Microsoft stack (C#, .NET, ASP.NET), I've recently been diving deeper into JavaScript and exploring the Ruby universe. Occasionally, I'll do a public speaking gig or write a blog post. When I'm not coding, I enjoy spending time with my family, watching hockey, and playing the occasional video game. You can also find me on Stack Overflow, Google Plus, and Twitter. Microsoft Certified Programming in HTML5 with JavaScript and CSS3 Specialist; MCPD Windows Developer 3.5
This entry was posted in Development, Mobile and tagged , , , , . Bookmark the permalink.

7 Responses to MonoDroid 101–Installation and Hello World with Mono for Android

  1. Pingback: Teaser–CodeStock Conference App for Android | The DevStop

  2. Pingback: Android Development with Mono For Android–Activities | The DevStop

  3. When i try and install Mono for Android it won’t install the plugin for Visual Studio

    • Mahir says:

      Same here, I followed the installation guide step by step….. I get the following error, Visual studio 2012 has been detected but its mono android extension is missing :/

      • David Ruttka says:

        Sorry, but I haven’t tried the plugin for VS2012. I have used MonoDevelop and VS2010. I’m not affiliated with Xamarin or their support channels; if you’re having trouble with the plugin for VS2012 you might have better luck searching their documentation. Thanks.

  4. Pavan @(pavanh)

    Hi very nice tutorial , very detailed and explanatory and helpful for beginners

  5. Anonymous says:

    installation failure

Thoughts?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s