Wei's Memo

A programmer's log.

Run Android in VirtualBox

Android emulator is VERY slow, because it emulates an ARM processor.

Install VirtualBox

Install VirtualBox if you have not. Download the binary here.

Download the Android x86 ISO file

Download an ISO file here

Create Your Android vm in VirtualBox Manager

Create a vm with 2G+ hard disk, from storage options mount the iso as the cd/dvd. Use bridged network.

Add custom screen sizes

If you want to android in portrait mode (i.e., a phone), use the following command to add a custom resolution to the .vbox file.

VBoxManage setextradata "YourVMName" "CustomVideoMode1" "480x800x16"

If the vm is running, you must poweroff and start the virtual machine to load the changed configuration (i.e., a simple reboot may not work)

Boot the virtual machine and choose “Installation - Install Android-x86 to harddisk”

  • Create partition, format it with ext3
  • install boot loader GRUB
  • mount system as readwrite

Edit the grub menu

Boot the vm and start in debug mode. If /dev/sda1 is not mount in rw mode, mount -o remount,rw /mnt edit the /mnt/grub/menu.lst file, append the following to the kernel parameters.

DPI=240 UVESA_MODE=480x800 


DPI=240 vga=ask 

(you can choose the screen size on boot)

Get the IP address of the emulator

Press Alt+F1, you will get a console. Type netcfg and write down the ip address. Press Alt+F7 to go back to GUI.

Connect with adb

adb connect [ip of the emulator] Then the emulator will show up in adb devices

Host+U is the sleep/awake button.

Mac Ip Forwarding

My mac’s internet sharing is not working. After a few days of googling and fiddling with the command lines, I found a solution to fix it.
en0 is the ethernet; en1 is wifi

sudo ipfw add divert natd all from any to any via en0
sudo ipfw add divert natd all from any to any via en1
sudo natd -interface en0 

Ruby Script for Taking Android Screenshot

This ruby script takes screenshots of all connected android devices.

Prepare the environment:

  • Install android sdk if you have not installed it yet.
  • Set ANDROID_HOME=<path-to-android-sdk>
  • Install the package:
git clone git@github.com:leohoo/auto-screenshot-android.git
cd auto-screenshot-android
bundle install
  • Connect android devices to your machine through usb.
  • Turn on debug mode of the devices, check the “Stay awake” option.

Run the following command to take screenshots of all the devices:

ruby browse-and-capture.rb "http://24log.jp/"

Take Screenshot of Android Devices From Command Line

I found that calabash-android is using this jar file to take screenshots.


To take a screenshot:

  • You need to install android sdk tools.
  • Set ANDROID_HOME to the path of the installed sdk(or you can set it from the command line).
  • Download screenshotTaker.jar.
  • Turn on debug mode of your device and connect it to your machine through usb.
  • Run the following command:
java -jar screenshotTaker.jar <screenshot-filename.png> [device-args]

device-args will be forward to adb command, so you can specify the serial-no when you have multiple devices connected. For example:

ANDROID_HOME=/DevTools/adt-bundle-mac-x86_64/sdk/ java -jar screenshotTaker.jar a.png -s 355659040404653

Calabash-android Console

Although there is no document about calabash-android console, calabash-android does support console.

calabash-android console <apk>

To start the app, use the following command.

irb(main):005:0> start_test_server_in_background

Rename Multiple Files at Once

As an iOS developer, sometimes you may want to rename the following files

  • header02.png
  • header02@2x.png
  • header02_down.png
  • header02_down@2x.png


  • header-backbtn.png
  • header-backbtn@2x.png
  • header-backbtn_down.png
  • header-backbtn_down@2x.png

Try this command:

for file in header02*; do mv $file ${file/header02/header-backbtn}; done

Apache Proxy to Local Port

<VirtualHost *>
        ServerName www.example.com
        ProxyPass / http://localhost:3000/
        ProxyPassReverse / http://localhost:3000/
        ProxyPreserveHost On

Root Nexus 7 With Mac

  • Install android SDK if you have not.
  • Download SuperSU and copy it to the root of Nexus 7’s SD card.
  • Download a recovery image
  • Boot Nexus 7 into fast boot mode.
  • Flash the recovery image using the following command.
fastboot flash recovery recovery-clockwork-touch-
  • After the command is executed, choose Recovery option from the Fastboot menu and boot the device into Recovery Mode.
  • Then navigate to Install zip from SD card option and hit Power button to select it. Then use volume keys to navigate to UPDATE-SuperSU-v1.04.zip file in tablet’s SD card and select it with Power button.
  • Reboot