Table of Contents

Getting the emulator

Minimal System requirements for the emulator

Installing the pre-built emulator

Instructions

sudo apt install ubuntu-emulator
sudo ubuntu-emulator create myinstance (you can use any name for "myinstance")
ubuntu-emulator run myinstance

To create a X86 instance, just give --arch=i386 to ubuntu-emulator create:

sudo ubuntu-emulator create --arch=i386 myinstance
ubuntu-emulator run myinstance

Notes

Maintenance

Until system-image works in the emulator, you can do the following to rebuild the image using the cached image:

$ sudo ubuntu-emulator create myoldinstance

Building from scratch

The Ubuntu emulator is composed of two parts: the runtime (what gets the emulator running) and the manager (the set of commands to start/stop and manage emulator instances).

To build the runtime:

$ sudo apt install phablet-tools git bzr

$ # install android build-dependencies
$ sudo apt build-dep android

$ # if we're on amd64, we need to pull in certain 32-bit packages explicitly
$ sudo apt install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev:i386 zlib1g-dev:i386

$ # this here is only needed if you didn't follow https://wiki.ubuntu.com/Touch/Porting before
$ sudo apt install schedtool openjdk-8-jdk g++-multilib bison flex

$ # and then work around the fact that libgl1-mesa-dev isn't Multi-Arch: same yet
$ sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/x86_64-linux-gnu/libGL.so

$ mkdir -p emulator/
$ phablet-dev-bootstrap emulator
$ cd emulator
$ source build/envsetup.sh
$ lunch aosp_arm-userdebug # or aosp_x86-userdebug for the x86 emulator
$ make -j<n>

To use the system.img that you just created, create an instance with ubuntu-emulator create --use-raw-disk and replace the system.img file available in the generated sdcard.img file (under ~/.local/share/ubuntu-emulator/<my instance>:

$ simg2img out/target/product/generic_x86/system.img out/target/product/generic_x86/system.raw
$ sudo mount ~/.local/share/ubuntu-emulator/myinstance/sdcard.img /tmp/mount1
$ sudo mount /tmp/mount1/system.img /tmp/mount2
$ sudo cp out/target/product/generic_x86/system.raw /tmp/mount2/var/lib/lxc/android/system.img
$ sudo umount /tmp/mount2
$ sudo umount /tmp/mount1

To build the manager:

sudo apt install golang-go
export GOPATH=$HOME/go
mkdir $GOPATH
export PATH=$PATH:$GOPATH/bin
go get launchpad.net/goget-ubuntu-touch/ubuntu-emulator

Username & password are:

phablet
phablet

To update your existing working tree to pull in new changes from the server, run repo sync.

For more information about how to use the repo command to manage your android working tree, see this page.

Support Status

Please check Support status to better know what is the current state of the emulator.

Using the emulator

After starting the emulator with the wrapper script, the following should be available:

Handling disk snapshots

Being able to create a snapshot and roll back to it is very useful for developers. Eg, developers can

Instructions

ubuntu-emulator handles disk snapshots:

$ ubuntu-emulator snapshot --help
Usage:
  ubuntu-emulator [OPTIONS] snapshot [snapshot-OPTIONS]

Create and revert to snapshots of the emulator instance name 'name' which was previously created

Help Options:
  -h, --help             Show this help message

Manipulates snapshots for emulator instance named 'name':
      --revert=          Reverts to the selected snapshot
      --create=          Creates the selected snapshot
      --revert-pristine  Reverts to the originally created snapshot

Help Options:
  -h, --help             Show this help message

Qcow2 images with snapshots are used by default when creating images with ubuntu-emulator create. The basic workflow is:

$ sudo ubuntu-emulator create trusty
$ ubuntu-emulator run trusty
<do work>
<shutdown or close the emulator with window/ctrl-c>
$ ubuntu-emulator snapshot --revert-pristine trusty
$ ubuntu-emulator run trusty
<perform tests in pristine environment>
<shutdown or close the emulator with window/ctrl-c>
$ ubuntu-emulator snapshot --revert-pristine trusty

Because a number of things happen on first boot after creating the image (or updating via system-image, which isn't supported yet, but will be), the first boot is very slow. You can workaround this by updating your pristine snapshot after your first boot, like so:

$ sudo ubuntu-emulator create trusty
$ ubuntu-emulator run trusty # first boot, be patient and wait until unity8 comes up
$ adb shell shutdown -h now  # wait until system is halted, then close the emulator with window/ctrl-c
$ ubuntu-emulator snapshot --create=pristine trusty

The above boots the emulator, cleanly shuts it down and then updates the pristine snapshot. See ubuntu-emulator snapshot --help for more details.

Keyboard Commands

Emulated Device Key

Keyboard Key

Power button

F7

Audio volume up button

KEYPAD_PLUS, Ctrl-F5

Audio volume down button

KEYPAD_MINUS, Ctrl-F6

Switch to previous layout orientation (for example, portrait, landscape)

KEYPAD_7, Ctrl-F11

Switch to next layout orientation (for example, portrait, landscape)

KEYPAD_9, Ctrl-F12

Known Issues

Extras

Touch/Emulator (last edited 2016-04-15 03:17:10 by tsimonq2)