File: android_emulator.md

package info (click to toggle)
chromium 73.0.3683.75-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,792,156 kB
  • sloc: cpp: 13,473,466; ansic: 1,577,080; python: 898,539; javascript: 655,737; xml: 341,883; asm: 306,070; java: 289,969; perl: 80,911; objc: 67,198; sh: 43,184; cs: 27,853; makefile: 12,092; php: 11,064; yacc: 10,373; tcl: 8,875; ruby: 3,941; lex: 1,800; pascal: 1,473; lisp: 812; awk: 41; jsp: 39; sed: 19; sql: 3
file content (104 lines) | stat: -rw-r--r-- 3,484 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Using an Android Emulator
Always use x86 emulators. Although arm emulators exist, they are so slow that
they are not worth your time.

## Building for Emulation
You need to target the correct architecture via GN args:
```gn
target_cpu = "x86"
```

## Creating an Emulator Image
By far the easiest way to set up emulator images is to use Android Studio.
If you don't have an [Android Studio project](android_studio.md) already, you
can create a blank one to be able to reach the Virtual Device Manager screen.

Refer to: https://developer.android.com/studio/run/managing-avds.html

Where files live:
 * System partition images are stored within the sdk directory.
 * Emulator configs and data partition images are stored within
   `~/.android/avd/`.

### Choosing a Skin
Choose a skin with a small screen for better performance (unless you care about
testing large screens).

### Choosing an Image
Android Studio's image labels roughly translate to the following:

| AVD "Target" | GMS? | Build Properties |
| --- | --- | --- |
| Google Play | This has GMS | `user`/`release-keys` |
| Google APIs | This has GMS | `userdebug`/`dev-keys` |
| No label | AOSP image, does not have GMS | `eng`/`test-keys` |

*** promo
If you're not sure which to use, **choose Google APIs**.
***

### Configuration
"Show Advanced Settings" > scroll down:
* Set internal storage to 4000MB (component builds are really big).
* Set SD card to 1000MB (our tests push a lot of files to /sdcard).

### Known Issues
 * Our test & installer scripts do not work with pre-MR1 Jelly Bean.
 * Component builds do not work on pre-KitKat (due to the OS having a max
   number of shared libraries).
 * Jelly Bean and KitKat images sometimes forget to mount /sdcard :(.
   * This causes tests to fail.
   * To ensure it's there: `adb -s emulator-5554 shell mount` (look for /sdcard)
   * Can often be fixed by editing `~/.android/avd/YOUR_DEVICE/config.ini`.
     * Look for `hw.sdCard=no` and set it to `yes`

### Cloning an Image
Running tests on two emulators is twice as fast as running on one. Rather
than use the UI to create additional avds, you can clone an existing one via:

```shell
$ tools/android/emulator/clone_avd.py \
    --source-ini ~/.android/avd/EMULATOR_ID.ini \
    --dest-ini ~/.android/avd/EMULATOR_ID_CLONED.ini \
    --display-name "Cloned Emulator"
```

## Starting an Emulator from the Command Line
Refer to: https://developer.android.com/studio/run/emulator-commandline.html.

*** promo
Ctrl-C will gracefully close an emulator.
***

### Basic Command Line Use
```shell
$ ~/Android/Sdk/emulator/emulator @EMULATOR_ID
```

### Running a Headless Emulator
You can run an emulator without creating a window on your desktop (useful for
`ssh`):
```shell
$ sudo apt-get install xvfb-run
$ xvfb-run ~/Android/Sdk/emulator/emulator -gpu off @EMULATOR_ID
```

### Writable system partition
Unlike physical devices, an emulator's `/system` partition cannot be modified by
default (even on rooted devices). If you need to do so (such as to remove a
system app), you can start your emulator like so:
```shell
$ ~/Android/Sdk/emulator/emulator -writable-system @EMULATOR_ID
```

### Remote Desktop
For better graphics performance, use virtualgl (Googlers, see
http://go/virtualgl):
```shell
$ vglrun ~/Android/Sdk/emulator/emulator @EMULATOR_ID
```

## Using an Emulator
 * Emulators show up just like devices via `adb devices`
   * Device serials will look like "emulator-5554", "emulator-5556", etc.