Template:Android emulation


(Difference between revisions)
Jump to: navigation, search
Perspectoff (Talk | contribs)
(Netflix Android App)

Current revision as of 21:26, 27 January 2013


Android emulation

Android-x86 in VirtualBox

The Android-x86 emulator is fast and efficient. It runs many apps (but not as many as the Android SDK emulator).

  • In Virtualbox (or QEMU, VMWare, or other virtual environment), install Android-x86 using the .iso downloaded to a hard drive (or, alternatively, burned to a CD or USB drive). Details:
  • From your favorite package manager (Muon, Synaptic, etc.) you can install the package virtualbox-qt, or from the command line:
sudo apt-get install virtualbox-qt

Both the proprietary binary for VirtualBox and the necessary dependency virtualbox-dkms will be installed at the same time.

  • Download a version of the Android-x86 image (.iso) from here. I used the latest version for ASUS (eee) Netbooks.
  • Start VirtualBox:
Menu -> Utilities -> VirtualBox
  • Create a new Virtual Machine for the Android x-86 OS:
VirtualBox -> New -> Next -> Name: Android -> OS Type: Operating System: Linux -> Version: Linux 2.6
-> Next -> Base Memory Size: 512 MB -> Next -> Virtual hard disk: Create new hard disk -> Next
-> File type: VDI -> Next -> Storage details: Dynamically allocated -> Next -> Location: Android
-> Size: 8 GB -> Summary: Create

Note: The Android 2.2 and 2.3 versions run very efficiently with only 256 MB Base Memory and require little hard disk space. For these versions I used only 2 GB for a virtual disk, of which 1 GB is used for the virtual ("fake") SDcard.

  • Tweak the VirtualBox Settings so that mouse capture is enabled for the newly created Android virtual machine. (Without this step you will not be able to use the mouse (or touchpad) in Android.):
Virtualbox -> Settings -> System -> Enable absolute pointing device (unticked)
  • The Android-x86 website says that only Soundblaster 16 works as a VirtualBox soundcard for Android, so change the Audio settings for VirtualBox:
VirtualBox -> Settings -> Audio -> Audio controller: Soundblaster 16
  • I use a wired Ethernet connection (with Android-x86 2.3). I therefore tweak the VirtualBox Settings to emulate a virtual PCnet-Fast III adapter, as recommended on the Android-x86 website.
VirtualBox -> Settings -> Network -> Enable Network Adapter (ticked) -> Attached to: NAT
-> Advanced -> Adapter Type: PCnet-Fast III (Am79C973) -> Ok
It is also possible to use the Attached to: Bridged Adapter mode with Name: eth0
  • Choose the downloaded Android-x86 (.iso) as a virtual CD-ROM to be used by VirtualBox:
VirtualBox -> Settings -> Storage -> Storage Tree: CD icon (Empty)
-> CD icon: Choose a virtual CD/DVD disk file ...
-> (click on the name of the downloaded android-x86-4.0-eeepc.iso file) -> Ok
  • Start the installation of Android-x86 in the VirtualBox virtual machine:
VirtualBox -> Start --> Installation -- Install Android-x86 to hard disk
-> Choose Partition: Create/Modify partitions -> Ok -> New -> Primary -> Size (in MB): 8588
-> Bootable -> Write -> Are you sure you want to write the partition table to disk? (yes or no): yes -> <Enter>
-> Quit -> Please select a partition to install Android-x86: sda1 LINUX VBOX HARDDISK -> OK ->
-> Choose filesystem: ext3 -> OK -> Are you sure to format the partition sda1? -> Yes
-> Do you want to install bootloader GRUB? -> Yes -> Do you want to install /system as read-write? yes

Note: the partition in this step is not on your physical hard drive but is entirely within the virtual hard drive created in the previous step. You will not erase anything on your physical hard drive during this step; only the contents within the virtual hard drive are at stake (and to your physical hard drive, the virtual hard drive appears only as an 8 GB file). There is no danger of harming your hard drive no matter what you do here! During installation of the Android OS, it makes sense to use the entire space of the newly created virtual hard drive (8 GB if following the instructions outlined above) for the Android OS.

  • After installation completes, the "Congratulations! Android-x386 is installed successfully" message appears.
  • At this stage I like to optionally Create a Fake SDcard (although there are several other options for SDcard emulation).
-> Create a fake SD card -> Please input the size of the sdcard.img in MB: 1024 -> Creating sdcard.img -> The fake SD card is created successfully.

I use half of the total partition space for my fake SDcard.img, so that if I created a 2 GB partition, I create a 1 GB fake SDcard.img. As long as plenty of space remains in the partition for the Android-x86 OS (I generally leave 1 GB for the OS), however, the size of the sdcard.img is unimportant and can be as large or small as desired.

  • After completing the initial Android setup (but before a "Reboot"), shutdown the Android virtual machine and tweak the VirtualBox settings so that the virtual CD-ROM no longer uses the Android-x86.iso virtual CD. (If you don't do this the virtual CD will be loaded again at reboot.):
VirtualBox -> Machine -> Close -> Power off the machine
-> Settings -> Storage -> CD-ROM icon (click) -> Host Drive DVD RW (select your physical CD/DVD drive, which should be listed) -> Passthrough ('ticked') -> OK
  • Restart the virtual machine and this time it should boot to the newly created virtual hard drive (with the newly installed Android-x86 OS on it). Whenever you Start the Android virtual machine in the future, it should boot straight into Android-x86.
  • During the first run, you can use the TAB button to navigate between options, or by clicking on the Android virtual machine window, you can "capture" the mouse (a blue pointer should appear) for use by the Android virtual machine. To return to the (K)Ubuntu normal (white) mouse pointer, use the <RIGHT-CTRL> button.
-> Start -> (setup initial options as desired)

Networking for Android-x86

  • By default the Android OS uses wireless networking. This can be linked to the (K)Ubuntu host's wireless adapter using either the NAT or Bridged networking modes of VirtualBox.
  • The Android 2.2 and 2.3 versions of Android-x86 also include wired Ethernet networking capabilities, which works well. Because I use Android-x86 in a wired environment, I mostly use Android-x86 2.3.
  • If your (K)Ubuntu host only has a wired ethernet connection, then you will use the eth0 connection within Android. In the VirtualBox Networking settings (Virtualbox -> Settings -> Network -> Attached to:) you can use NAT or Bridged Adapter (eth0) but if you intend to use any server functions from Android, you must use the Bridged Adapter (eth0). Start the Android virtual machine after choosing the VirtualBox settings.
Wired networking for Android-x86 RC 4.0RC1
  • (Note: I could not get wired networking to function properly in the Android-x86 3.2 version.)
  • These instructions were tested using the android-x86-4.0-RC1-eeepc version of Android-x86 and were adapted from those given here.
  • Make sure the host computer's firewall is off while testing connections.
  • Once the Android system has fully booted within the virtual machine, go to the root command-line using <ALT-F1>.
  • The command line can also be reached through the Terminal Emulator:
Android -> Home icon -> App menu icon -> Terminal Emulator
You may then need to become the superuser from the command-line: su
  • (This step may be optional and is suggested only if needed for troubleshooting. It is necessary if using the "route add" command in the next step.) From the command line, enable the wired networking port using ifconfig. Use an unused IP address on the main LAN:
ifconfig eth0
  • (This step may be optional and is suggested only if needed for troubleshooting.) For the eth0 connection set a route to the default gateway (this should be the IP address of your router / DHCP server on your LAN):
route add default gw dev eth0
  • For some reason, my connection would not work unless a DHCP connection is enabled:
netcfg eth0 dhcp
  • Test to make sure traffic is reaching the router:
  • Set a DNS provider (examples are for Google, for Comodo, and for OpenDNS).
setprop net.dns1
  • Return to the Android environment using <ALT-F7>.
  • Following these steps, start the Browser. If you get a webpage, then the connection works. If not, make sure all firewalls are off (for your VirtualBox host) while testing your setup.

Installing apps

  • Use either the Android 2.2 or Android 2.3 version of Android-x86 for wired networking. Most (but not all) apps will work with wired connections.
  • The following apps work (both wirelessly and with wired connections):
  • These apps do not work:
  • Netflix (stock app from Amazon Appstore or the modified XDA-developers' version). The Netflix app requires Android version 2.3 or later, in general, but I have not been able to get Netflix to work with any Android-x86 version yet.

Modified apps

Note: These are for testing only.

For the Android-x86 4.0RC1 version with an imperfect wired connection, I needed to download from the command-line:

  • Go to the command line using <ALT-F1>.
  • Change to the /sdcard directory and download the app using wget:
cd /sdcard
wget http://ubuntuguide.org/images/Amazon_Appstore-release.apk
  • Return to the Android GUI environment (<ALT-F7>). Use the OpenManager file browser to navigate to the /sdcard directory, where the downloaded xxx.apk file should be found. Click on it to install it.
  • In other versions with working wired or wireless connections (i.e. Android 2.2 and 2.3), the apps can be downloaded directly from the Android Browser.

Usage tips

  • In Android-x86 2.2 and 2.3, the "Back" function is the right mouse button or "ESC." To go to the "Home" screen, use the "Windows" button of the keyboard. A quick <double-click> with the captured mouse will alternately zoom in and zoom out (for many apps). The <PGUP>, <PGDN>, and arrow keys of the physical keyboard can be used to navigate the Android-x86 display.
  • To disable the pop-up Android keyboard, untick the "Android keyboard" in the Android -> Settings -> Language & keyboard settings.
  • If you have created a VirtualBox virtual machine for your Android OS entitled Android, then it can be started using the command (which can be placed in a menu item):
VirtualBox -startvm "Android"
  • You can also start VirtualBox in fullscreen mode:
VirtualBox -fullscreen -startvm "Android"
However, for this to be beneficial, you would also have to change the display settings of the Android-x86 OS to be larger as well. For example, if using a 1024x768 screen, the UVESA_MODE=1024x768 option should be added to the Grub bootup settings. This can be done by editing the Grub settings using the vi editor. Boot Android-x86 into the "Debug mode" to enter the command-line environment, then edit /mnt/grub/menu.lst:
vi /mnt/grub/menu.lst
and add UVESA_MODE=1024x768 to an existing line or create an entirely new entry that includes the option. In vi use the i option to start inserting text and ESC to stop. Save and quit the vi editor using :wq. Reboot the Android system for the changes to appear.
  • Portrait mode can be enabled by creating custom video modes for VirtualBox. Using the instructions here I create four custom video modes for the four portrait resolutions that I like: 320x480 (a size that approximates a smartphone size), 540x720 (which works well for me in fullscreen mode on my 1024x768 monitor), 504x672 (which works well for me in windowed mode on my monitor), and 450x600 (which is easily maneuvered in window mode). These modes are all 16-bit modes (24-bit modes don't work for me in these sizes). (As in the other examples, my virtual machine is named Android.)
VBoxManage setextradata "Android" "CustomVideoMode1" "320x480x16"
VBoxManage setextradata "Android" "CustomVideoMode2" "540x720x16"
VBoxManage setextradata "Android" "CustomVideoMode3" "504x672x16"
VBoxManage setextradata "Android" "CustomVideoMode4" "450x600x16"
I then edit the Android Grub menu (as above) and add entries for my custom resolutions, using UVESA_MODE=320x480 DPI=160, UVESA_MODE=540x720 DPI=160, UVESA_MODE=504x672 DPI=160, and UVESA_MODE=450x600 DPI=160, each in a different Grub entry, to correspond to the custom video modes I created. When I start the Android virtual machine I can select my resolution and orientation by choosing from one of these newly created Grub menu entries. (Note that by setting a 16-bit resolution for the CustomVideoModes, the Android-x86 Grub settings must correspondingly be DPI=160 instead of DPI=240.)
  • An easy method to change the display size of Android-x86 is the "Scale" mode of VirtualBox. In this mode, the size of Android-x86 will be scaled to whatever size the VirtualBox window is stretched. It is a menu item in VirtualBox, or can be reached from the hotkeys: <RIGHT-CTRL>-<HOME>.

Android SDK emulator

Android SDK for Linux is a 32-bit Android emulator/software development kit. It incorporates a QEMU virtual machine framework as part of its installation. It provides a fully functional Android environment and apps can be installed from (and run within) the emulator. However, it is a very top-heavy and slow environment to use for emulation unless you have a very powerful computer with lots of RAM and processing power.

  • Install the pre-requisites:
sudo apt-get install ia32-libs default-jre

Note: ia32-libs is only needed on a 64-bit system. default-jre will also install open-jdk6-jre.

  • Download the Android SDK (e.g. android-skd_r18-linux.tgz from here and extract it (using Ark, for example) to its default folder ~/android-sdk-linux/ (i.e. /home/user/android-sdk-linux/):
wget http://dl.google.com/android/android-sdk_r18-linux.tgz
tar xvf android-sdk_r18-linux.tgz
  • Add the /home/user/android-sdk-linux/tools and /home/user/android-sdk-linux/platform-tools/ directories to the PATH for the user (or for the system) by editing /home/user/.profile (or /etc/profile for system-wide use):
sudo nano /home/user/.profile

and adding this line at the end:

export PATH=/home/user/android-sdk-linux/tools/:/home/user/android-sdk-linux/platform-tools/:$PATH

Save the file and then log out/log in (or reboot if changes were made to the system-wide config file).

  • Change to the /home/user/android-sdk-linux/tools directory and start the Android SDK Manager:
cd /home/user/android-sdk-linux/tools
  • Install the "Tools" by ticking the appropriate boxes -> Install Packages
  • Choose which Android version to emulate and install it.
  • Android SDK Manager -> Android 4.0.3 (API 15) (ticked) -> Install packages
  • Still within the Android SDK Manager, create a virtual machine ("AVD") with the desired Android system in it. The WXGA800 skin gives a widescreen (tablet) appearance:
Android SDK Manager -> Tools -> Manage AVDs -> New
-> Name: Android4 -> Target: Android 4.0.3 - API Level 15 -> Size (of virtual SDcard): 2 Gb -> Skin: Built-in: WXGA800 -> Hardware: Device ram size (in Mb): <click> on 1024 -> 512
-> Create AVD
At the time of the creation of the virtual machine it is possible to adjust the amount of RAM dedicated to your device (I personally only dedicate 384 Mb) or leave it at the default of 1024 Mb if your system has plenty of RAM.
  • Close the Android SDK Manager. Now the new Android virtual machine can be started from the command line terminal. (This command can also be added to a menu item.)
emulator -avd Android4
where Android4 is the name of the virtual machine created in the previous step.
  • On less powerful computers, the startup of the emulator can be slow. Be patient.

Networking for Android SDK

Networking from the Android SDK virtual machine to my host computer's wired Ethernet connection was transparent upon installation. I required no additional configuration and all networking functions were operational.

Installing an app

Netflix Android App

  • A Netflix app for the Android market is available here or through the Amazon Appstore. The Netflix app requires Android 2.3 or later. In my Android 4.0.3 emulator the stock Netflix app (from the Amazon Appstore) successfully downloads and installs and I am able to login to my account and hear audio when streaming content, but no video. I have not yet tried the XDA-developers' version.
  • A better solution is to use the Netflix in Wine bundle, which runs the Windows version of Netflix in a modified Wine environment. This solution works well.

Other references

  • A graphical installation guide Softpedia (2009).

Other Android Virtual Machines

Other Android Resources

  • AOSP -- Android Open Source Project
  • CyanogenMod -- creates custom ROMs for devices not supported by Google Android so that the open source Android OS (AOSP) can run on them. Also see their wiki.
  • F-Droid is the repository for free and open source software (almost all of it ad-free) for the Google Android platform.
Personal tools
Going Tribal