blob: 9a72634a10119e1e9137409f3e3546fe8988eb42 [file] [log] [blame] [view]
Andrew Grieveae094e392018-06-15 16:10:221# Using an Android Emulator
Nate Fischer16f94532019-03-27 20:51:072Always use x86 emulators (or x86\_64 for testing 64-bit APKs). Although arm
3emulators exist, they are so slow that they are not worth your time.
Andrew Grieveae094e392018-06-15 16:10:224
Nate Fischeracbbaab2019-04-23 16:46:205*** note
6**Note:** apps with native code must be compiled specifically for the device
7architecture, so make sure your copy of the app supports x86. Also, be aware the
8Play Store may not display ARM-only applications for an x86 emulator. The steps
9below show how to locally compile chromium-based apps for x86.
10***
11
Andrew Grieveae094e392018-06-15 16:10:2212## Building for Emulation
13You need to target the correct architecture via GN args:
Nate Fischer7cbdeae2019-01-24 20:29:1514```gn
Nate Fischer16f94532019-03-27 20:51:0715target_cpu = "x86" # or "x64" if you have an x86_64 emulator
Andrew Grieveae094e392018-06-15 16:10:2216```
17
18## Creating an Emulator Image
19By far the easiest way to set up emulator images is to use Android Studio.
20If you don't have an [Android Studio project](android_studio.md) already, you
21can create a blank one to be able to reach the Virtual Device Manager screen.
22
23Refer to: https://developer.android.com/studio/run/managing-avds.html
24
25Where files live:
26 * System partition images are stored within the sdk directory.
27 * Emulator configs and data partition images are stored within
28 `~/.android/avd/`.
29
Nate Fischer7cbdeae2019-01-24 20:29:1530### Choosing a Skin
31Choose a skin with a small screen for better performance (unless you care about
32testing large screens).
Andrew Grieveae094e392018-06-15 16:10:2233
Nate Fischer7cbdeae2019-01-24 20:29:1534### Choosing an Image
35Android Studio's image labels roughly translate to the following:
36
Nate Fischeracbbaab2019-04-23 16:46:2037| AVD "Target" | Virtual Device Configuration tab | GMS? | Build Properties |
38| --- | --- | --- | --- |
39| Google Play | "Recommended" (the default tab) | This has GMS | `user`/`release-keys` |
40| Google APIs | "x86 Images" | This has GMS | `userdebug`/`dev-keys` |
41| No label | "x86 Images" | AOSP image, does not have GMS | `eng`/`test-keys` |
Nate Fischer7cbdeae2019-01-24 20:29:1542
43*** promo
Nate Fischeracbbaab2019-04-23 16:46:2044**Tip:** if you're not sure which to use, choose **Google APIs** under the **x86
45Images** tab in the Virtual Device Configuration wizard.
Nate Fischer7cbdeae2019-01-24 20:29:1546***
47
48### Configuration
49"Show Advanced Settings" > scroll down:
50* Set internal storage to 4000MB (component builds are really big).
51* Set SD card to 1000MB (our tests push a lot of files to /sdcard).
52
53### Known Issues
Andrew Grieveae094e392018-06-15 16:10:2254 * Our test & installer scripts do not work with pre-MR1 Jelly Bean.
55 * Component builds do not work on pre-KitKat (due to the OS having a max
56 number of shared libraries).
57 * Jelly Bean and KitKat images sometimes forget to mount /sdcard :(.
58 * This causes tests to fail.
59 * To ensure it's there: `adb -s emulator-5554 shell mount` (look for /sdcard)
60 * Can often be fixed by editing `~/.android/avd/YOUR_DEVICE/config.ini`.
61 * Look for `hw.sdCard=no` and set it to `yes`
62
Andrew Grievea0190fd2018-06-15 17:52:4963### Cloning an Image
64Running tests on two emulators is twice as fast as running on one. Rather
65than use the UI to create additional avds, you can clone an existing one via:
66
67```shell
Nate Fischer7cbdeae2019-01-24 20:29:1568$ tools/android/emulator/clone_avd.py \
Andrew Grievea0190fd2018-06-15 17:52:4969 --source-ini ~/.android/avd/EMULATOR_ID.ini \
70 --dest-ini ~/.android/avd/EMULATOR_ID_CLONED.ini \
71 --display-name "Cloned Emulator"
72```
73
Andrew Grieveae094e392018-06-15 16:10:2274## Starting an Emulator from the Command Line
75Refer to: https://developer.android.com/studio/run/emulator-commandline.html.
76
Nate Fischer7cbdeae2019-01-24 20:29:1577*** promo
78Ctrl-C will gracefully close an emulator.
79***
Andrew Grieveae094e392018-06-15 16:10:2280
Nate Fischer7cbdeae2019-01-24 20:29:1581### Basic Command Line Use
82```shell
83$ ~/Android/Sdk/emulator/emulator @EMULATOR_ID
Andrew Grieveae094e392018-06-15 16:10:2284```
Nate Fischer7cbdeae2019-01-24 20:29:1585
86### Running a Headless Emulator
87You can run an emulator without creating a window on your desktop (useful for
88`ssh`):
89```shell
Nate Fischer9cbee2432019-04-10 14:51:5890$ ~/Android/Sdk/emulator/emulator -no-window @EMULATOR_ID
Nate Fischer7cbdeae2019-01-24 20:29:1591```
92
93### Writable system partition
94Unlike physical devices, an emulator's `/system` partition cannot be modified by
95default (even on rooted devices). If you need to do so (such as to remove a
96system app), you can start your emulator like so:
97```shell
98$ ~/Android/Sdk/emulator/emulator -writable-system @EMULATOR_ID
99```
100
101### Remote Desktop
102For better graphics performance, use virtualgl (Googlers, see
103http://go/virtualgl):
104```shell
105$ vglrun ~/Android/Sdk/emulator/emulator @EMULATOR_ID
Andrew Grieveae094e392018-06-15 16:10:22106```
107
108## Using an Emulator
109 * Emulators show up just like devices via `adb devices`
110 * Device serials will look like "emulator-5554", "emulator-5556", etc.
111