blob: 68fd7642f614b3424c79eaef84943b44f930b199 [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
5## Building for Emulation
6You need to target the correct architecture via GN args:
Nate Fischer7cbdeae2019-01-24 20:29:157```gn
Nate Fischer16f94532019-03-27 20:51:078target_cpu = "x86" # or "x64" if you have an x86_64 emulator
Andrew Grieveae094e392018-06-15 16:10:229```
10
11## Creating an Emulator Image
12By far the easiest way to set up emulator images is to use Android Studio.
13If you don't have an [Android Studio project](android_studio.md) already, you
14can create a blank one to be able to reach the Virtual Device Manager screen.
15
16Refer to: https://developer.android.com/studio/run/managing-avds.html
17
18Where files live:
19 * System partition images are stored within the sdk directory.
20 * Emulator configs and data partition images are stored within
21 `~/.android/avd/`.
22
Nate Fischer7cbdeae2019-01-24 20:29:1523### Choosing a Skin
24Choose a skin with a small screen for better performance (unless you care about
25testing large screens).
Andrew Grieveae094e392018-06-15 16:10:2226
Nate Fischer7cbdeae2019-01-24 20:29:1527### Choosing an Image
28Android Studio's image labels roughly translate to the following:
29
30| AVD "Target" | GMS? | Build Properties |
31| --- | --- | --- |
32| Google Play | This has GMS | `user`/`release-keys` |
33| Google APIs | This has GMS | `userdebug`/`dev-keys` |
34| No label | AOSP image, does not have GMS | `eng`/`test-keys` |
35
36*** promo
37If you're not sure which to use, **choose Google APIs**.
38***
39
40### Configuration
41"Show Advanced Settings" > scroll down:
42* Set internal storage to 4000MB (component builds are really big).
43* Set SD card to 1000MB (our tests push a lot of files to /sdcard).
44
45### Known Issues
Andrew Grieveae094e392018-06-15 16:10:2246 * Our test & installer scripts do not work with pre-MR1 Jelly Bean.
47 * Component builds do not work on pre-KitKat (due to the OS having a max
48 number of shared libraries).
49 * Jelly Bean and KitKat images sometimes forget to mount /sdcard :(.
50 * This causes tests to fail.
51 * To ensure it's there: `adb -s emulator-5554 shell mount` (look for /sdcard)
52 * Can often be fixed by editing `~/.android/avd/YOUR_DEVICE/config.ini`.
53 * Look for `hw.sdCard=no` and set it to `yes`
54
Andrew Grievea0190fd2018-06-15 17:52:4955### Cloning an Image
56Running tests on two emulators is twice as fast as running on one. Rather
57than use the UI to create additional avds, you can clone an existing one via:
58
59```shell
Nate Fischer7cbdeae2019-01-24 20:29:1560$ tools/android/emulator/clone_avd.py \
Andrew Grievea0190fd2018-06-15 17:52:4961 --source-ini ~/.android/avd/EMULATOR_ID.ini \
62 --dest-ini ~/.android/avd/EMULATOR_ID_CLONED.ini \
63 --display-name "Cloned Emulator"
64```
65
Andrew Grieveae094e392018-06-15 16:10:2266## Starting an Emulator from the Command Line
67Refer to: https://developer.android.com/studio/run/emulator-commandline.html.
68
Nate Fischer7cbdeae2019-01-24 20:29:1569*** promo
70Ctrl-C will gracefully close an emulator.
71***
Andrew Grieveae094e392018-06-15 16:10:2272
Nate Fischer7cbdeae2019-01-24 20:29:1573### Basic Command Line Use
74```shell
75$ ~/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
82$ sudo apt-get install xvfb-run
83$ xvfb-run ~/Android/Sdk/emulator/emulator -gpu off @EMULATOR_ID
84```
85
86### Writable system partition
87Unlike physical devices, an emulator's `/system` partition cannot be modified by
88default (even on rooted devices). If you need to do so (such as to remove a
89system app), you can start your emulator like so:
90```shell
91$ ~/Android/Sdk/emulator/emulator -writable-system @EMULATOR_ID
92```
93
94### Remote Desktop
95For better graphics performance, use virtualgl (Googlers, see
96http://go/virtualgl):
97```shell
98$ vglrun ~/Android/Sdk/emulator/emulator @EMULATOR_ID
Andrew Grieveae094e392018-06-15 16:10:2299```
100
101## Using an Emulator
102 * Emulators show up just like devices via `adb devices`
103 * Device serials will look like "emulator-5554", "emulator-5556", etc.
104