blob: 49ab0b9b61a328f9c36021118e28e24cfbe6e68c [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 Grieveae094e392018-06-15 16:10:2263## Starting an Emulator from the Command Line
64Refer to: https://developer.android.com/studio/run/emulator-commandline.html.
65
Nate Fischer7cbdeae2019-01-24 20:29:1566*** promo
67Ctrl-C will gracefully close an emulator.
68***
Andrew Grieveae094e392018-06-15 16:10:2269
Nate Fischer7cbdeae2019-01-24 20:29:1570### Basic Command Line Use
71```shell
Andrew Grievec8f2703d2019-05-22 20:04:4472$ # List virtual devices that you've created:
73$ ~/Android/Sdk/emulator/emulator -list-avds
74$ # Start a named device:
Nate Fischer7cbdeae2019-01-24 20:29:1575$ ~/Android/Sdk/emulator/emulator @EMULATOR_ID
Andrew Grieveae094e392018-06-15 16:10:2276```
Nate Fischer7cbdeae2019-01-24 20:29:1577
78### Running a Headless Emulator
79You can run an emulator without creating a window on your desktop (useful for
80`ssh`):
81```shell
Nate Fischer9cbee2432019-04-10 14:51:5882$ ~/Android/Sdk/emulator/emulator -no-window @EMULATOR_ID
Andrew Grievec8f2703d2019-05-22 20:04:4483$ # This also works for new enough emulator builds:
84$ ~/Android/Sdk/emulator/emulator-headless @EMULATOR_ID
85```
86
87### Running Multiple Emulators
88Tests are automatically sharded amongst available devices. If you run multiple
89emulators, then running test suites becomes much faster. Refer to the
90"Multiple AVD instances" section of these [emulator release notes](
91https://androidstudio.googleblog.com/2018/11/emulator-28016-stable.html)
92for more about how this works.
93```shell
Andrew Grievec214adb2019-05-28 01:39:2394$ # Start 8 emulators. Press Ctrl-C to stop them all.
95$ ( for i in $(seq 8); do ~/Android/Sdk/emulator/emulator @EMULATOR_ID -read-only & done; wait )
Nate Fischere44e0f02019-05-29 20:09:5396$ # Start 12 emulators. More than 10 requires disabling audio on some OS's. Reducing cores increases parallelism.
Andrew Grievec214adb2019-05-28 01:39:2397$ ( for i in $(seq 12); do ~/Android/Sdk/emulator/emulator @EMULATOR_ID -read-only -no-audio -cores 2 & done; wait )
Nate Fischer7cbdeae2019-01-24 20:29:1598```
99
100### Writable system partition
101Unlike physical devices, an emulator's `/system` partition cannot be modified by
102default (even on rooted devices). If you need to do so (such as to remove a
103system app), you can start your emulator like so:
104```shell
105$ ~/Android/Sdk/emulator/emulator -writable-system @EMULATOR_ID
106```
107
Andrew Grieveae094e392018-06-15 16:10:22108## 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