VMware Ubuntu virtual machine for Android development

I’m currently gearing up to do some Android app development after making some headway through this helpful Android dev book, “Professional Android 2 Application Development.

I decided to create a small Ubuntu-based virtual machine that is dedicated solely to Android app development.  This gives me several benefits:

  • Small and clean environment dedicated only to Android development work.
  • Ability to create VM snapshots before undertaking any potentially destructive actions.
  • Extreme mobility by having the virtual machine files stored on my dropbox account so I can start up the development VM anywhere I go.

Here are the steps to create an Ubuntu virtual machine specifically for Android development.  Note: these instructions assume you already have some basic knowledge of Ubuntu and VMware workstation/fusion.

Virtual machine install
Install from 32-bit Ubuntu 10.10 ISO image to a VM with these selections: Linux version Ubuntu, 12GB vdisk, 2 vCPUs, 3GB RAM.

It’s recommended to use 32-bit OS instead of 64-bit to avoid potential problems with libraries. However, if really want to go with a 64-bit OS, need to install 32-bit compat libraries:

apt-get install ia32-libs

After a fresh install/reboot, use apt-get or the package manager to bring machine fully up to date then reboot to complete the update.

Install VMware Tools for Ubuntu for overall improved performance.
——————————–
VMware Workstation menu: VM -> Install VMware Tools
Copy VMwareTools-xxx.tar.gz from the DVD to your home directory (~jared for this example)

cd ~jared
tar -zxvf VMwareTools-xxx.tar.gz
cd vmware-tools-distrib
sudo ./vmware-install.pl
install using default values

Ensure VMware Tools survives future kernel upgrades
——————————————————————-
Place this script inside /etc/rc.local

# Automatically install vmware tools modules after a kernel upgrade.
# Installing new vmware tools modules causes network to go down and up.
# (The pcnet32 module is swapped out for vmxnet driver)
# This may have adverse effect on network-aware programs already running.
# So is safer to reboot to ensure everything is working properly.
if [ ! -e /lib/modules/`uname -r`/misc/.vmware_installed ]; then
      printf "\nDetected absence of VM Tools- starting the modules compiling.\n\n"
      /usr/bin/vmware-config-tools.pl --default
      VMToolsVersion=`/usr/bin/vmware-config-tools.pl --help 2>&1 | awk '$0 ~ /^VMware Tools [0-9]/ { print $3,$4 }'`
      printf "\nNewly installed VM Tools version: $VMToolsVersion\n\n"
      touch /lib/modules/`uname -r`/misc/.vmware_installed
      depmod -a
      printf "\n  *** REBOOTING ***  Ensure a clean system with VMTools loaded.\n\n"
      reboot
fi

————–

Create the .vmware_installed file:

touch /lib/modules/`uname -r`/misc/.vmware_installed

Change System->Preferences->Monitors to an increased resolution. I like to use 1152×864 (4:3)

Installation of software for Android development:

Install in this order:
1. Java
2. Eclipse
3. Android SDK
4. ADT plugin.

Activate the software repository for Sun Java.
———————————-

note: JDK 1.4 or GCJ (GNU complier for Java) are NOT supported for Android development.

Activate the Partner repository so can include Sun’s Java software in list of available software packages. (as opposed to openJDK)

System -> Administration -> Synaptic Package Manager -> Settings-> Repositories -> Other Software -> check Canonical Partners.

Close and reload Synaptic Package Manager.

Install Sun JDK6 (not the JRE)

sudo apt-get install sun-java6-jdk

Ubuntu automatically selects java-6-openjdk for the default java, to change this:

update-java-alternatives -l
update-java-alternatives -s java-6-sun

or

update-alternatives --config java
# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection    Path                                      Priority   Status
------------------------------------------------------------
0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
* 2            /usr/lib/jvm/java-6-sun/jre/bin/java       63        manual mode
Press enter to keep the current choice[*], or type selection number: 2
# java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Server VM (build 19.1-b02, mixed mode)

Eclipse installation
—————————-
At present time, Ubuntu package manager doesn’t offer >= Eclipse 3.6 (Helios) so get directly from eclipse.org/downloads and download the Eclipse Classic package: ~170MB tgz file.

move the tgz to your ~/Applications directory.
tar -zxvf eclipse-SDK-3.6.1-linux-gtk.tar.gz

double-click and run ~/Applications/eclipse/eclipse
Accept default value for workspace location.

Installing Android SDK
———————————
Download from
http://developer.android.com/sdk/index.html

uncompress the tgz into ~/Applications directory
cd ~/Applications/android-sdk-linux_x86/

tools/android update sdk

My personal preference is to develop for Android 2.2 (API Level 8) or higher, so I select the SDK Platform Android APIs and the samples for these versions.  I also select the latest Documentation, Android SDK Tools and Platform-tools.

Installing the Android Development Tools (ADT) plugin
—————————————————–
ADT plugin installation is done through Eclipse.

Start Eclipse, then select Help > Install New Software -> Add

In the “Add Repository” dialog that appears, enter “ADT Plugin” for the Name and the following URL for the Location:
https://dl-ssl.google.com/android/eclipse/

In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
In the next window, you’ll see a list of the tools to be downloaded. Click Next.
Read and accept the license agreements, then click Finish.
When the installation completes, restart Eclipse.

Now ADT Plugin needs to be configured:
Select Window > Preferences… to open the Preferences panel
Select Android from the left panel.

For the SDK Location in the main panel, click Browse… and locate your downloaded SDK directory at:
/home/jared/Applications/android-sdk-linux_x86/

Click Apply, then OK.

Restart Eclipse.

After all these installations on a 12GB vdisk:

#  df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              12G  5.4G  5.4G  50% /

There is plenty of room left over for your Android development work.

This entry was posted in Android, Linux. Bookmark the permalink.