LAC07: Xamarin for Android with Genymotion

2 Flares Twitter 0 Facebook 0 StumbleUpon 2 Google+ 0 LinkedIn 0 2 Flares ×

Xamarin and Genymotion

One of the key parts of productive development is having the right development environment, and using Genymotion with Xamarin for Android is a fantastic.

Having done a fair bit of Android work beforehand I know only too well how painful it is working with the Android emulator provided with the Android SDK. Its really slow and very temperamental…I’d say out of all the main emulators (iOS. Windows and Android), that the Android one is the worst.

That’s why I opted for something different!

Genymotion

I’ve used Genymotion on previous Android projects and have to say its a pleasure to work with. It runs using Virtual Box, and provides the best option for debugging and testing your Android apps on a desktop computer. And it works beautifully with Xamarin and Visual Studio!

To make the case even more compelling, the non-commercial version of Genymotion is totally free, and the indie licence is only €99. At €99 Genymotion will easily pay for itself in time saved waiting for the Android emulator!

Getting Started with Genymotion

This guide is deliberately brief because working getting started with Genymotion is a piece of cake. I did think it was worth documenting my steps though!

Installing Genymotion

Setting up Genymotion is pretty much as simple as running the installer – everything is taken care of and it just works. I’d write it up more fully but its really that straight forward!

I should note that you do need to install Virtual Box beforehand. There are also some issues using Virtual Box and Hyper-V at the same time but Scott Hanselman has written an article about dealing with Virtual Box and Hyper-V.

Creating a New Virtual Device

Once you’ve got everything installed you just need to launch up Genymotion and you should get a screen something like this:

Genymotion Empty Main Screen

You’ll want to add a new virtual device so press the “Add” button. This next screen should show you a list of available devices. If it doesn’t you should get a prompt to connect using your account to Genymotion online – simply doing this should bring up the list of devices.

Genymotion Available Devices

Here you can filter by Android version and device model – I wanted a fairly standard and well used device so I chose the “Google Nexus 5”. Once you’ve selected your device, just click “Next”, where you’ll be prompted to give it a name (I just left mine as the name provided):

Genymotion Confirm Devices

At this stage Genymotion will start downloading the device – the rough download size for my selection was 209mb. Once the download is complete you should get a confirmation box, where you can just press the “Finish” button.

Now your Genymotion main screen should show the device you’ve downloaded:

Genymotion Main Screen

Just select the device and click the “Play” button – this will initialize the device, and spin up Android on it. It may take a minute but believe me its a hell of a lot quicker than the standard emulator!! Once its loaded you should have a fully usable Android VM:

Genymotion Android Home Screen

Debugging on the Genymotion VM

I thought I’d just wrap up by quickly going over how you debug your app on the Genymotion VM. Its amazingly simple with Xamarin and Visual Studio!

I just created a sample project called CodenutzComics using the “Blank App (Xamarin.Forms.Portable)” template. Once everything was created I chose the Android project (CodenutzComics.Android) and set it as the start-up project. Notice on the image below how Xamarin and Visual Studio have automatically recognised the Genymotion VM running:

Xamarin Visual Studio Genymotion VM Highlighted

This means that I’m ready to go and that the debugging should work seamlessly. Now I just choose “Start Debugging” (or press F5), and the project will be built and deployed onto the Genymotion VM automatically.

Genymotion Hello Xamarin

Wrapping up

All in all this is really impressive, from the ease of installing Genymotion to how simple it was to debug the Xamarin app straight from Visual Studio on the Genymotion VM.

I have to say that Genymotion is a huge leap forward over the standard Android VM and is well worth the €99 (or free for personal use). If you’re doing Android development, whether it be with Xamarin, Android Studio or Eclipse, just go get Genymotion now, you won’t regret it!

, , ,

  • iraqi masoom

    awesome app, Introduction too …..:)

  • Ahmed S. Tahir

    I just installed Genymotion after unsuccessful attempt at running Xamarin Android Player. When I run my code through Xamarin Studio, the “Select Device” popup does not show Genymotion VM though it is up and running. What can be the reason? I am using Windows 8 and did not install VirtualBox with Genymotion as it got installed with Xamarin Android Player

    • It should be – you might need to restart adb

      • Ahmed S. Tahir

        How do I do that?

        By the way this is what I just did: I uninstalled Genymotion, Xamarin Android Player and VirtualBox and restarted my computer. Then I downloaded Genymotion with VirtualBox and installed. I thought maybe there was a conflict of XAP and Genymotion. Unfortunately I still don’t see the emulator when running my code from Xamarin Studio.

        • Adb is the android debugging bridge. Its part of the android sdk which you will already have installed if you’re using xamarin.

          Try opening the command prompt and running “adb devices” – if its not in your path you’ll need to go to the location of your android sdk. If your genymotion devices isn’t listed its probably worth trying “adb kill-server” and “adb start-server” – then try running “adb devices” again.

          If it still isn’t showing up get the IP of your genymotion emulator (its actually in the title bar if you stretch it right out). Then run “adb connect #.#.#.#” (where #.#.#.# is your genymotion IP address). This should really sort your problem

          There is one other thing to check – make sure that both genymotion and xamarin are pointing at the same android sdk location – its in the settings for each one.

          Full adb documentation: http://developer.android.com/tools/help/adb.html

          • Ahmed S. Tahir

            You’re a lifesaver Matt!
            “adb connect #.#.#.#” did the trick as genymotion device was not originally listed.
            Thanks for your prompt help.

          • Glad to help 🙂

          • Ahmed S. Tahir

            Matt I know that this is beyond the scope of this article but can you also guide me about how can I use an actual device for debugging on localhost? I mean I know that “localhost” will not work as is and that’s why I use 10.0.3.2 for Genymotion emulator but what should I write there for an actual device?
            Thanks in advance.

          • If you connect an actual device via USB Xamarin usually picks it up and lets you deploy to it – you do have to enable USB debugging though (http://www.kingoapp.com/root-tutorials/how-to-enable-usb-debugging-mode-on-android.htm)

          • Ahmed S. Tahir

            Well I have the device detected by Xamarin Studio and I have also successfully deployed the app on it but the issue is that I don’t know how to access the localhost web service on it. Like I said, for genymotion emulator, I have used 10.0.3.2 instead of localhost and it works but how do I do it on actual device

          • I’ve actually not done that yet but I’ll give it a go later. The stack overflow answer below suggests you can use IP address 10.0.2.2

            http://stackoverflow.com/questions/11328554/android-connect-to-pcs-localhost-when-debugger-on-mobile-device

          • Ahmed S. Tahir

            Well Matt first of all thanks for all the support. However 10.0.2.2 is for emulator only (like Genymotion uses 10.0.3.2). I had already visited that Stack Overflow link but it does not solve the problem as you can see one of the comments saying that it does not answer the question and agree to that. For now, I will do my work on emulator. Thanks again!

  • Hanix
  • keerthana bala

    Hai, I am using mac os. Wants connect Genymotion to deploy on Xamarin Studio. Can you please help to connect?? Thanks a lot.

The Essential App Marketing Kit
Subscribe To My Newsletter To Get an Entire Chapter From The Book for FREE
Never display this again
2 Flares Twitter 0 Facebook 0 StumbleUpon 2 Google+ 0 LinkedIn 0 2 Flares ×