Emulator

Differences between revisions 54 and 55
Revision 54 as of 2014-05-13 22:14:58
Size: 9607
Editor: bd222d17
Comment:
Revision 55 as of 2014-05-14 15:06:05
Size: 9731
Editor: bd222d17
Comment:
Deletions are marked like this. Additions are marked like this.
Line 94: Line 94:

= Support Status =

Please check [[/Support|Support status]] to better know what is the current state of the emulator.

Getting the emulator

Minimal requirements for the emulator

  • 512MB of RAM dedicated for the emulator
  • 4GB of disk space
  • OpenGL capable desktop drivers (due the OpenGLES 2.0 translator)

Installing the pre-built emulator

Instructions

  • Install the ubuntu-emulator package
  • Create an instance (and select the desired arch to use)
  • Run the emulator

sudo apt-get install ubuntu-emulator
sudo ubuntu-emulator create 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

  • By default the latest built image from devel-proposed channel is used.
    • This can be changed during creation with the --channel and --revision options.
  • XDG_CACHE_DIR/ubuntuimage is used to download images; it is shared with ubuntu-device-flash.
  • Images are stored in XDG_DATA_DIR/ubuntu-emulator.
  • To update to a latest image; it is safe to create over the previous instance (upgrade option comming soon).
  • Once migrated to this ubuntu-emulator-images and android-emulator can be safely removed.
  • All references to run-emulator.sh and build-emulator-sdcard.sh do no apply anymore.
  • Snapshotting is taken care of with the snapshot subcommand from ubuntu-emulator.
  • If ubuntu-emulator run fails with libGL error: Couldn't dlopen libudev.so.1 or libudev.so.0, driver detection may be broken on amd64, this is bug:1291333. You can work around this by doing sudo apt-get install libudev1:i386

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

To build

$ sudo apt-get install phablet-tools git bzr

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

$ # if we're on amd64, we need to pull in certain 32-bit packages explicitly
$ sudo apt-get 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-get install schedtool openjdk-6-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

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 following should be available:

  • Adb
    • Emulator will appear in the output of $ adb devices, and will, once fully booted allow
      $ adb shell
      access into ubuntu.
  • SSH access
    • SSH is enabled by default in the emulator, but you can only access it via localhost (QEMU handles the routes and NAT internally). All you need is to forward the target SSH port to a known port at your host:
      $ adb forward tcp:9999 tcp:22
      $ ssh phablet@localhost -p 9999
  • Telnet access
    • Once launched graphical window title will show a port number, e.g. 5554. Connect to that over telnet, to send hardware events to the emulator
      $ telnet 127.0.0.1 5554
      Trying 127.0.0.1...
      Connected to 127.0.0.1.
      Escape character is '^]'.
      Android Console: type 'help' for a list of commands
      OK
      help
      Android console command help:
      
          help|h|?         print a list of commands
          event            simulate hardware events
          geo              Geo-location commands
          gsm              GSM related commands
          cdma             CDMA related commands
          kill             kill the emulator instance
          network          manage network settings
          power            power related commands
          quit|exit        quit control session
          redir            manage port redirections
          sms              SMS related commands
          avd              control virtual device execution
          window           manage emulator window
          qemu             QEMU-specific commands
          sensor           manage emulator sensors
      
      try 'help <command>' for command-specific help
      OK
  • Autopilot
    1. Start up emulator with ubuntu-emulator as per above.

    2. Get emulator serial:
      • $ adb devices
        List of devices attached
        emulator-5554 device
        emulator-5556 device
    3. Pass -s emulator-XXXX to phablet-config and phablet-test* commands

    4. otherwise use same as described in https://wiki.ubuntu.com/Touch/Testing#Testing_your_Ubuntu_Touch_Code_before_submission, but without "phablet-flash" step for the time being.

Handling disk snapshots

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

  • develop features, etc on the image, then package them up, roll back the image and test on a pristine image
  • save time on system-image upgrade testing
  • do multiple test runs, reverting to the pristine image between runs to cut down on variances
  • verify bugs in the image easily
  • etc

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

  • The first boot might take a few minutes as it generates the ssh key, install the click packages and so on. It shouldn't take too much though, always check with adb if the emulator is still running correctly (e.g. check with top).
  • It's quite common for Qemu to hang while booting (like an I/O-type hang), just abort and restart the emulator (still needs proper debugging).
  • If Unity8 fails to start, make sure your i386 GL driver is properly in place (check for error libGL.so.1: cannot open shared object file: No such file or directory when starting the emulator). If everything goes well, you should see 'qemu.gles=1' in the qemu kernel parameters.

Extras

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