I wanted to make note of a couple of quick tips for Android development around emulators.
The standard Android emulator can be painfully slow. Genymotion makes a drop-in replacement that’s blazingly fast. I’ve used it for years, and highly recommend it for any serious developer.
Genymotion achieves this by running an x86 version of Android in Virtualbox. This has a couple of implications.
Services on localhost
Virtualbox has several networking modes used to expose a guest virtual machine (in this case, an emulated Android device). Genymotion sets up two, a NAT service to connect to the outside world, and a “host-only” (HO) device. The HO device allows connecting to the host machine.
The connection happens through a virtual interface named “vboxnet0”. To connect to a service on the host machine, you need to use the IP address of this interface. I find this generally ends up as 192.168.56.1. To check, you can use any tool that lists the information for your network interfaces. For example, on Linux or OSX, you can use ifconfig. You should see something like this:
inet 192.168.56.1 netmask 0xffffff00 broadcast 192.168.56.255
The number after “inet” is the IP address you need.
Google Play Services
Many apps depend on Google Play (GP) services. Genymotion doesn’t ship with GP. Fortunately, you can install a bundle containing GP yourself.
This is really easy to do. Many write-ups will tell you to install both an ARM-x86 translator, and an ARM version of GP. That’s no longer necessary. http://opengapps.org/ hosts both ARM and x86 versions. To get GP loaded, follow these steps:
- Go to http://opengapps.org/
- Select “x86” under Platform.
- Select the Android release that corresponds to your virtual device Android version.
- Pick a variant. (I’ve installed “stock”, but anything down to “nano” should do.)
- Download the zip package.
- Run Genymotion and bring up a device. (These latter steps must be done for each device.)
- Drag and drop the zip package to the virtual device. (Note this may only work for versions 2.7.2 and later of Genymotion.)
You should see the following dialog pop up:
Hit “OK”. Wait for the file to finish “flashing”. Ideally you would reboot your device using adb, but this hasn’t worked for me. I’ve had no problems after “powering off” the device with the (virtual) power button. It won’t fully shutdown, so you’ll still have to kill the virtual device.
Couchbase Mobile Training
Now that you’re set up with a better emulator environment, take a look at the Couchbase Mobile Training for a step-by-step look at everything you need to develop with NoSQL for mobile.
You can follow me personally at @HodGreeley