UP | HOME
../../

AVD Android Virtual Devices

Table of Contents

1 Abstract

A tool to create and manage "standard" Android Virtual Devices is part of the Android SDK. This page is a compact version of Devlopers'.

  1. Prerequisite: CLI, bash, shell environment, PATH,
  2. Prerequisite: Java, JAVAHOME, etc
  3. Prerequisite: ../SDK/ Android SDK Overview
  4. Remember our overall preference: Command Line Use over GUI Menu Clicks.

2 Create an AVD or two

  1. % /usr/local/android-sdk-linux/tools/android avd & {New in 2019: Outputs: The "android" command is deprecated. … use Android Studio. For Now.}
  2. Create one, two, or three AVDs (Android Virtual Device). Different names, but otherwise identical.
  3. Recommend cloning Nexus 5. CPU armeabi-v71 32-bit; SD card size = 512 or 1024 MB. Mine are named pmNX5a, pmNX5b, pmNX5c.
  4. This will create several files in .android/ of your home directory. % du -sh ~/.android/ Mine is 5.3 GB.

2.1 My AVD pmNX5a.avd/

% ls -g ~/.android/avd/pmNX5a.avd/

total 2770472
-rw------- 1 pmateti          0 May 24 21:55 cache.img
-rw-rw-r-- 1 pmateti        364 May 24 23:19 config.ini
-rw-rw-r-- 1 pmateti         49 May 24 23:36 emulator-user.ini
-rw-rw-r-- 1 pmateti       1370 May 24 23:46 hardware-qemu.ini
-rw-rw-r-- 1 pmateti  104857600 May 24 22:34 sdcard.img
-rw-rw-r-- 1 pmateti 2312830976 May 24 21:56 snapshots.img
-rw-rw-r-- 1 pmateti       1444 May 24 21:56 snapshots.img.default-boot.ini
-rw-rw-r-- 1 pmateti  209715200 May 24 21:53 userdata.img
-rw------- 1 pmateti  209715200 Jun  2 07:05 userdata-qemu.img
-rw------- 1 pmateti          6 Jun  2 06:34 userdata-qemu.img.lock

2.2 pmNX5a.avd contd.

  1. man file The command named file can recognize the content of a file regardless of its name. Part of Linux/Android background.
  2. % file ~/.android/avd/pmNX5a.avd/*.img
    cache.img:         empty 
    sdcard.img:        x86 boot sector
    snapshots.img:     QEMU QCOW Image (v2), 524288000 bytes
    userdata.img:      Linux rev 1.0 ext4 filesystem data, 
      UUID=57f8f4bc-abf4-655f-bf67-946fc0f9f25b (extents) (large files)
    userdata-qemu.img: Linux rev 1.0 ext4 filesystem data, 
      UUID=57f8f4bc-abf4-655f-bf67-946fc0f9f25b (needs journal recovery) 
      (extents) (large files)
    
  3. .ini and .cfg Text files describing the initialization/ config to various tools. You can edit. But carefully.
  4. For detailed descriptions: http://developer.android.com/tools/devices/emulator.html

3 Starting AVDs

  1. % android-sdk-linux/tools/emulator -avd pmNX5a & This invokes the emulator directly without the AVD Manager. Takes several arguments useful to us in labs.
  2. Emulator is based on QEMU. So, it can take -quemu option arguments also.
  3. Wait until the AVD windows shows completion of Android boot. Can take a minute or two.

3.1 Starting Three AVDs

  1. Start pmNX5b and pmNX5c also.
  2. % /usr/local/android-sdk-linux/platform-tools/adb devices
    List of devices attached 
    emulator-5554   device
    emulator-5556   device
    emulator-5558   device
    
  3. The 5554 .. are port numbers on the PC. Each AVD uses two ports; e.g., 5554 (for telnet console) and 5555 (for adb).

3.2 Multiple adb shell Sessions

  1. Invoke three terminal (e.g., konsole) sessions. Invoke adb shell to one AVD in each.
  2. Explore the content of the AVD. E.g., with ls etc.
  3. Configure the IP addresses, etc. so that the three AVDs can see (e.g., ping) each other on the network.
  4. root@generic:/ # ifconfig eth0
eth0: ip 10.0.2.15 mask 255.255.255.0 flags [up broadcast running multicast]

3.3 Install APKs in Snapshots

  1. adb install ~/Downloads/aDownLoaded.apk can install the file on your PC ~/Downloads/aDownLoaded.apk as an APK into the snapshot.

3.4 toolbox

  1. root@generic:/ # ls -l /system/bin/toolbox
  2. size = 139040 bytes. Android, ARM CPU, program. Several tools compiled and linked into one program. E.g., mount -> toolbox and kill -> toolbox
  3. You may want to install busybox Three to four times bigger than toolbox.
  4. Refresher: Invoking a program; passing arguments to the process.

3.5 Install busybox into the emulator-5554

  1. We are installing busybox just make network setup easier; better route etc.
  2. This is a part of rooting. But: Incomplete. Not persistent.
  3. http://busybox.net/downloads/binaries/latest/ Download a busybox binary matching the AVDs CPU. ~pmateti/Downloads is where I saved it.
  4. Notice prompt strings
    1. % Logged into Linux PC as myself, not root
    2. root@generic:/ # Logged into AVD pmNX5 as root
  5. % adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system You may have to change details; e.g., mtdblock03 may have to be mtdblock0
  6. % adb push ~pmateti/Downloads/busybox-armv7l /system/xbin

3.6 Install busybox into the emulator-5554, contd.

  1. % adb shell
  2. root@generic:/ # chmod 555 /system/xbin/busybox-armv7l set execute permission
  3. root@generic:/ # mv /system/xbin/busybox-armv7l /system/xbin/busybox not required
  4. root@generic:/ # busybox gives a list of all commands within busybox
  5. size comparison
    root@generic:/ # ls -l /system/bin/toolbox /system/xbin/busybox
    -rwxr-xr-x root     shell      139040 2013-12-05 14:07 toolbox
    -r-xr-xr-x root     root      1109128 2014-06-03 19:15 busybox
    

4 [./AVD-Networking.org-TBD][Networking AVDs]]

5 File System

  1. Refresher: ext4, vfat, yaffs2, mount, umount, …
  2. Ubuntu currently does not support yaffs2. See http://askubuntu.com/questions/234258/how-to-mount-a-yaffs2-filesystem

5.1 Mount Table of emulator-5554 pmNX5

root@generic:/ # mount
rootfs / rootfs ro,relatime 0 0
tmpfs /dev tmpfs rw,seclabel,nosuid,relatime,mode=755 0 0
devpts /dev/pts devpts rw,seclabel,relatime,mode=600 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,seclabel,relatime 0 0
selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
none /acct cgroup rw,relatime,cpuacct 0 0
none /sys/fs/cgroup tmpfs rw,seclabel,relatime,mode=750,gid=1000 0 0
tmpfs /mnt/asec tmpfs rw,seclabel,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,seclabel,relatime,mode=755,gid=1000 0 0
none /dev/cpuctl cgroup rw,relatime,cpu 0 0
/dev/block/mtdblock0 /system ext4 ro,seclabel,relatime,data=ordered 0 0
/dev/block/mtdblock1 /data ext4 rw,seclabel,nosuid,nodev,noatime,nomblk_io_submit,data=ordered 0 0
/dev/block/vold/179:0 /mnt/media_rw/sdcard vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/fuse /storage/sdcard fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

5.2 Mount Table of emulator-5554 pmNX5

  1. The /dev/block/mtdblock0 /dev/block/mtdblock1 /dev/block/vold/179:0 are block devices. Persistent. That is, you can examine them off-line.
  2. Quiz: How do these "map" to the .imp files shown from the ~/.android/avd/pmNX5a.avd/ ?
  3. The rootfs, tmpfs, devpts, proc, sysfs, selinuxfs, debugfs are file volumes that Linux OS created from the OS-internal information. Not persistent. They are reconstructed each time the device boots.

6 References

7 Task: Emulator of Android SDK

The emulator is part of the standard bundle when you installed the SDK. Write down the pathname of the SDK installation. On my PC, it is /usr/local/android-sdk-linux/

The ls -l listings below are pruned.

7.1 /usr/local/platform-tools

-rwxrwxr-x 1 pmateti pmateti 2237804 Aug  4 19:14 adb
drwxrwxr-x 2 pmateti pmateti    4096 Aug  4 19:14 api
-rwxrwxr-x 1 pmateti pmateti 1482432 Aug  4 19:14 fastboot
-rwxrwxr-x 1 pmateti pmateti 1124741 Aug  4 19:14 sqlite3
drwxrwxr-x 3 pmateti pmateti    4096 Aug  4 19:14 systrace

7.2 /usr/local/tools

-rwxrwxr-x 1 pmateti pmateti    3498 Aug  4 19:14 android
drwxrwxr-x 2 pmateti pmateti    4096 Aug  4 19:14 bin64
-rwxrwxr-x 1 pmateti pmateti    3286 Aug  4 19:14 ddms
-rwxrwxr-x 1 pmateti pmateti  538144 Aug  4 19:14 emulator
-rwxrwxr-x 1 pmateti pmateti 6574024 Aug  4 19:14 emulator64-arm
-rwxrwxr-x 1 pmateti pmateti 4387752 Aug  4 19:14 emulator64-crash-service
-rwxrwxr-x 1 pmateti pmateti 6725144 Aug  4 19:14 emulator64-x86
-rwxrwxr-x 1 pmateti pmateti   92400 Aug  4 19:14 emulator-check
-rwxrwxr-x 1 pmateti pmateti   12191 Aug  4 19:14 mksdcard
-rwxrwxr-x 1 pmateti pmateti    1293 Aug  4 19:14 monitor
-rwxrwxr-x 1 pmateti pmateti    3176 Aug  4 19:14 monkeyrunner
drwxrwxr-x 7 pmateti pmateti    4096 Aug  4 19:14 proguard
drwxrwxr-x 3 pmateti pmateti    4096 Aug  4 19:14 qemu
-rwxrwxr-x 1 pmateti pmateti    2259 Aug  4 19:14 screenshot2
  1. To give you a realistic enough feel as to what rooting entails, we do "it" on the AVD. Re-read the lecture notes on rooting. Follow the procedure described in the notes to root an AVD of your choice.
  2. Rooting an AVD is always going to be simpler than rooting a real device. The main reason is bootloader image you chose ought to have been already unlocked. Read Rooting an Android Device
  3. Note that /system does not contain the initial ramdisk needed during boot and kernel. Libraries??
  4. Look at the lunch script

% ls /usr/local/bootimg

bootinfo mkbootimg repackramdisk splitboot umkbootimg unpack unpackramdisk

7.3 config.ini

  1. Inserting path names has no effect

7.4 hardware-qemu.ini

% /usr/local/android-sdk-linux/tools/emulator -avd NX442API19 -show-kernel
  1. File will be created, if absent. Updated. Based on the contents of the ~/.android/avd/name.avd/ dir.
% rm hardware-qemu.ini* userdata* cache.img* ramdisk.img* 

% cat ~/.emulatorconsoleauthtoken IFVeQaKaCjexUF/3Sutherland:~/.android/avd/NX442API19.avd

#+beginsrc bash disk.cachePartition.path = ~/.android/avd/NX442API19.avd/cache.img kernel.path = /usr/local/android-sdk-linux/system-images/android-19/default/armeabi-v7a//kernel-qemu disk.ramdisk.path = usr/local/android-sdk-linux/system-images/android-19/default/armeabi-v7a//ramdisk.img disk.systemPartition.initPath = ~.android/avd/NX442API19.avd/system.img disk.dataPartition.path = ~/.android/avd/NX442API19.avd/userdata-qemu.img ramdisk.img also

kernel-qemu -> Nexus-4/occam-lmy48t/boot/zImage ramdisk.img -> Nexus-4/occam-lmy48t/boot/ramdisk.img system.img -> Nexus-4/occam-lmy48t/system-raw.img

kernel.path = ~/.android/avd/NX442API19.avd/kernel-qemu disk.ramdisk.path = ~/.android/avd/NX442API19.avd/ramdisk.img disk.systemPartition.initPath = ~/.android/avd/NX442API19.avd/system.img disk.systemPartition.size = 840m disk.dataPartition.path = ~/.android/avd/NX442API19.avd/userdata-qemu.img disk.dataPartition.initPath = /usr/local/android-sdk-linux/system-images/android-18/default/armeabi-v7a//userdata.img disk.dataPartition.size = 200m avd.name = NX442API19

Concatenated QEMU options: usr/local/android-sdk-linux/tools/emulator64-arm -dns-server 127.0.1.1 -serial android-kmsg -serial null -android-hw /home/pmateti.android/avd/NX442API19.avd/hardware-qemu.ini -append 'qemu=1 androidboot.hardware=goldfish console=ttyS0 android.qemud=1 android.checkjni=1 qemu.gles=0'

emulator -sysdir sysdirpnm -system systemimgpnm \ -ramdisk ramdiskimgpnm\ -data userdataimgpnm -kernel kernelqemupnm \ -sdcard sdcard.img \ -skindir sdk/emulator/skins \ -skin WVGA800 -scale 0.7 -memory 512 -partition-size 1024

my run % emulator -avd NX442API19 -debug kernel -debug init -show-kernel -no-boot-anim

adb -s emulator-5554 emu kill

emulator: Probing system image file for partition type: home/pmateti.android/avd/NX442API19.avd/system.img

8 Shell

#!/usr/bin/env bash

ANDROIDBUILDOUT=/path/to/android/build/output/ ANDROIDSDKLINUX=/path/to/android/sdk ANDROIDBUILD=${ANDROIDBUILDOUT}/android/target/product/generic

${ANDROIDSDKLINUX}/tools/emulator \ -sysdir ${ANDROIDBUILD} \ -system ${ANDROIDBUILD}/system.img \ -ramdisk ${ANDROIDBUILD}/ramdisk.img \ -data ${ANDROIDBUILD}/userdata.img \ -kernel ${ANDROIDSDKLINUX}/system-images/android-18/armeabi-v7a/kernel-qemu \ -skindir ${ANDROIDSDKLINUX}/platforms/android-18/skins \ -skin WVGA800 \ -scale 0.7 \ -memory 512 \ -partition-size 1024 #+endsrc

9 References

  1. https://developer.android.com/studio/run/managing-avds Create and manage virtual devices. Required Reading.

10 End


Copyright © 2019 www.wright.edu/~pmateti • 2019-01-17