Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 1 | # Using an Android Emulator |
Nate Fischer | 16f9453 | 2019-03-27 20:51:07 | [diff] [blame] | 2 | Always use x86 emulators (or x86\_64 for testing 64-bit APKs). Although arm |
| 3 | emulators exist, they are so slow that they are not worth your time. |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 4 | |
Nate Fischer | 4a49458 | 2020-03-12 18:08:51 | [diff] [blame] | 5 | [TOC] |
Nate Fischer | acbbaab | 2019-04-23 16:46:20 | [diff] [blame] | 6 | |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 7 | ## Building for Emulation |
| 8 | You need to target the correct architecture via GN args: |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 9 | ```gn |
Nate Fischer | 16f9453 | 2019-03-27 20:51:07 | [diff] [blame] | 10 | target_cpu = "x86" # or "x64" if you have an x86_64 emulator |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 11 | ``` |
| 12 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 13 | ## Running an Emulator |
| 14 | |
Erik Chen | 254ec1cc | 2024-01-18 02:11:49 | [diff] [blame] | 15 | ### Googler-only Emulator Instructions |
| 16 | |
| 17 | See http://go/clank-emulator/ |
| 18 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 19 | ### Using Prebuilt CIPD packages |
| 20 | |
| 21 | Chromium has a set of prebuilt images stored as CIPD packages. These are used |
| 22 | by various builders to run tests on the emulator. Their configurations are |
Haiyang Pan | b06f846d | 2021-12-21 17:41:55 | [diff] [blame] | 23 | currently stored in [`//tools/android/avd/proto`](../tools/android/avd/proto/). |
Andrew Grieve | 1b9be14 | 2022-02-10 04:07:00 | [diff] [blame] | 24 | You can run this command to list them: |
| 25 | ```sh |
| 26 | tools/android/avd/avd.py list |
| 27 | ``` |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 28 | |
Haiyang Pan | 0fca0dc | 2024-03-25 17:50:30 | [diff] [blame] | 29 | | Configurations | Android Version | CPU Arch| AVD Target | Builder | |
| 30 | |:-------------- |:--------------- |:------- |:---------- |:------- | |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 31 | | `generic_android26.textpb` | 8.0 (O) | x86 | google_apis | N/A | |
| 32 | | `generic_android27.textpb` | 8.1 (O_MR1) | x86 | google_apis | N/A | |
| 33 | | `android_28_google_apis_x86.textpb` | 9 (P) | x86 | google_apis | [android-pie-x86-rel][android-pie-x86-rel] | |
Haiyang Pan | 0fca0dc | 2024-03-25 17:50:30 | [diff] [blame] | 34 | | `android_29_google_apis_x86.textpb` | 10 (Q) | x86 | google_apis | N/A | |
| 35 | | `android_30_google_apis_x86.textpb` | 11 (R) | x86 | google_apis | [android-11-x86-rel][android-11-x86-rel] | |
| 36 | | `android_31_google_apis_x64.textpb` | 12 (S) | x86_64 | google_apis | [android-12-x64-rel][android-12-x64-rel] | |
| 37 | | `android_32_google_apis_x64_foldable.textpb` | 12L (S_V2) | x86_64 | google_apis | [android-12l-x64-dbg-tests][android-12l-x64-dbg-tests] | |
| 38 | | `android_33_google_apis_x64.textpb` | 13 (T) | x86_64 | google_apis | [android-13-x64-rel][android-13-x64-rel] | |
| 39 | | `android_34_google_apis_x64.textpb` | 14 (U) | x86_64 | google_apis | [android-14-x64-rel][android-14-x64-rel] | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 40 | |
| 41 | You can use these configuration files to run the same emulator images locally. |
| 42 | |
| 43 | [android-pie-x86-rel]: https://ci.chromium.org/p/chromium/builders/ci/android-pie-x86-rel |
Haiyang Pan | b06f846d | 2021-12-21 17:41:55 | [diff] [blame] | 44 | [android-11-x86-rel]: https://ci.chromium.org/p/chromium/builders/ci/android-11-x86-rel |
Haiyang Pan | 2a55a45 | 2022-03-03 08:18:33 | [diff] [blame] | 45 | [android-12-x64-rel]: https://ci.chromium.org/p/chromium/builders/ci/android-12-x64-rel |
Haiyang Pan | 0fca0dc | 2024-03-25 17:50:30 | [diff] [blame] | 46 | [android-12l-x64-dbg-tests]: https://ci.chromium.org/p/chromium/builders/ci/android-12l-x64-dbg-tests |
| 47 | [android-13-x64-rel]: https://ci.chromium.org/p/chromium/builders/ci/android-13-x64-rel |
| 48 | [android-14-x64-rel]: https://ci.chromium.org/p/chromium/builders/ci/android-14-x64-rel |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 49 | |
Haiyang Pan | f5faf23 | 2020-11-06 18:10:34 | [diff] [blame] | 50 | #### Prerequisite |
| 51 | |
| 52 | * Make sure KVM (Kernel-based Virtual Machine) is enabled. |
| 53 | See this |
| 54 | [link](https://developer.android.com/studio/run/emulator-acceleration#vm-linux) |
| 55 | from android studio for more details and instructions. |
| 56 | |
| 57 | * You need to have the permissions to use KVM. |
| 58 | Use the following command to see if you are in group `kvm`: |
| 59 | |
| 60 | ``` |
| 61 | $ grep kvm /etc/group |
| 62 | ``` |
| 63 | |
| 64 | If your username is not shown in the group, add yourself to the group: |
| 65 | |
| 66 | ``` |
| 67 | $ sudo adduser $USER kvm |
| 68 | $ newgrp kvm |
| 69 | ``` |
| 70 | |
Erik Chen | 254ec1cc | 2024-01-18 02:11:49 | [diff] [blame] | 71 | You need to log out and log back in so the new groups take effect. |
Peter Wen | 96981e20 | 2021-08-06 21:13:40 | [diff] [blame] | 72 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 73 | #### Running via the test runner |
| 74 | |
| 75 | The android test runner can run emulator instances on its own. In doing so, it |
| 76 | starts the emulator instances, runs tests against them, and then shuts them |
| 77 | down. This is how builders run the emulator. |
| 78 | |
| 79 | ##### Options |
| 80 | |
| 81 | * `--avd-config` |
| 82 | |
| 83 | To have the test runner run an emulator instance, use `--avd-config`: |
| 84 | |
| 85 | ``` |
| 86 | $ out/Debug/bin/run_base_unittests \ |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 87 | --avd-config tools/android/avd/proto/android_33_google_apis_x64.textpb |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 88 | ``` |
| 89 | |
| 90 | * `--emulator-count` |
| 91 | |
| 92 | The test runner will launch one instance by default. To have it run multiple |
| 93 | instances, use `--emulator-count`: |
| 94 | |
| 95 | ``` |
| 96 | $ out/Debug/bin/run_base_unittests \ |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 97 | --avd-config tools/android/avd/proto/android_33_google_apis_x64.textpb \ |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 98 | --emulator-count 4 |
| 99 | ``` |
| 100 | |
sbingler | 8d91e8c | 2024-04-23 16:36:58 | [diff] [blame] | 101 | * `--emulator-enable-network` |
| 102 | |
| 103 | The test runner runs the emulator without network access by default. To have |
| 104 | it run with network access, use `--emulator-enable-network`: |
| 105 | |
| 106 | ``` |
| 107 | $ out/Debug/bin/run_base_unittests \ |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 108 | --avd-config tools/android/avd/proto/android_33_google_apis_x64.textpb \ |
sbingler | 8d91e8c | 2024-04-23 16:36:58 | [diff] [blame] | 109 | --emulator-enable-network |
| 110 | ``` |
| 111 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 112 | * `--emulator-window` |
| 113 | |
| 114 | The test runner runs the emulator in headless mode by default. To have it run |
| 115 | with a window, use `--emulator-window`: |
| 116 | |
| 117 | ``` |
| 118 | $ out/Debug/bin/run_base_unittests \ |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 119 | --avd-config tools/android/avd/proto/android_33_google_apis_x64.textpb \ |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 120 | --emulator-window |
| 121 | ``` |
| 122 | |
| 123 | #### Running standalone |
| 124 | |
| 125 | The test runner will set up and tear down the emulator on each invocation. |
| 126 | To manage emulator lifetime independently, use `tools/android/avd/avd.py`. |
| 127 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 128 | ##### Options |
| 129 | |
| 130 | * `--avd-config` |
| 131 | |
| 132 | This behaves the same as it does for the test runner. |
| 133 | |
| 134 | ``` |
| 135 | $ tools/android/avd/avd.py start \ |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 136 | --avd-config tools/android/avd/proto/android_33_google_apis_x64.textpb |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 137 | ``` |
| 138 | |
| 139 | > Note: `avd.py start` will start an emulator instance and then terminate. |
Ian Struiksma | e6fcbf0 | 2021-05-03 23:18:06 | [diff] [blame] | 140 | > To shut down the emulator, use `adb emu kill`. |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 141 | |
sbingler | 8d91e8c | 2024-04-23 16:36:58 | [diff] [blame] | 142 | * `--enable-network` |
| 143 | |
| 144 | Like the test runner, `avd.py` runs the emulator without network access by |
| 145 | default. To enable network access, use `--enable-network`: |
| 146 | |
| 147 | ``` |
| 148 | $ tools/android/avd/avd.py start \ |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 149 | --avd-config tools/android/avd/proto/android_33_google_apis_x64.textpb \ |
sbingler | 8d91e8c | 2024-04-23 16:36:58 | [diff] [blame] | 150 | --enable-network |
| 151 | ``` |
| 152 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 153 | * `--emulator-window` |
| 154 | |
| 155 | Like the test runner, `avd.py` runs the emulator in headless mode by default. |
| 156 | To have it run with a window, use `--emulator-window`: |
| 157 | |
| 158 | ``` |
| 159 | $ tools/android/avd/avd.py start \ |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 160 | --avd-config tools/android/avd/proto/android_33_google_apis_x64.textpb \ |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 161 | --emulator-window |
| 162 | ``` |
| 163 | |
Haiyang Pan | b06f846d | 2021-12-21 17:41:55 | [diff] [blame] | 164 | * `--gpu-mode GPU_MODE` |
| 165 | |
| 166 | Override the mode of hardware OpenGL ES emulation indicated by the AVD. |
| 167 | See "emulator -help-gpu" for a full list of modes. |
| 168 | |
| 169 | * `--no-read-only` |
| 170 | |
| 171 | `avd.py` runs the emulator in read-only mode by default. To run a modifiable |
| 172 | emulator, use `--no-read-only`: |
| 173 | |
| 174 | ``` |
| 175 | $ tools/android/avd/avd.py start \ |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 176 | --avd-config tools/android/avd/proto/android_33_google_apis_x64.textpb \ |
Haiyang Pan | b06f846d | 2021-12-21 17:41:55 | [diff] [blame] | 177 | --no-read-only |
| 178 | ``` |
| 179 | |
Peter Wen | b105afb | 2021-12-07 20:24:36 | [diff] [blame] | 180 | * `--wipe-data` |
| 181 | |
Haiyang Pan | e5e2bc0 | 2023-10-20 19:31:53 | [diff] [blame] | 182 | Reset the /data partition to the factory defaults. This removes all user |
| 183 | settings from the AVD. |
Peter Wen | b105afb | 2021-12-07 20:24:36 | [diff] [blame] | 184 | |
| 185 | ``` |
| 186 | $ tools/android/avd/avd.py start \ |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 187 | --avd-config tools/android/avd/proto/android_33_google_apis_x64.textpb \ |
Peter Wen | b105afb | 2021-12-07 20:24:36 | [diff] [blame] | 188 | --wipe-data |
| 189 | ``` |
| 190 | |
Haiyang Pan | b06f846d | 2021-12-21 17:41:55 | [diff] [blame] | 191 | * `--writable-system` |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 192 | |
Victor Vianna | 725b107 | 2022-03-04 16:02:59 | [diff] [blame] | 193 | Makes system & vendor image writable. It's necessary to run |
| 194 | ``` |
| 195 | adb root |
| 196 | adb remount |
| 197 | ``` |
| 198 | after the emulator starts. |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 199 | |
Haiyang Pan | f5faf23 | 2020-11-06 18:10:34 | [diff] [blame] | 200 | * `--debug-tags` |
| 201 | |
| 202 | `avd.py` disables the emulator log by default. When this option is used, |
| 203 | emulator log will be enabled. It is useful when the emulator cannot be |
| 204 | launched correctly. See `emulator -help-debug-tags` for a full list of tags. |
Haiyang Pan | 7c2d20f | 2024-02-20 21:59:28 | [diff] [blame] | 205 | Use `--debug-tags=all` if you want to output all logs (warning: it is quite |
Peter Wen | b105afb | 2021-12-07 20:24:36 | [diff] [blame] | 206 | verbose). |
Haiyang Pan | f5faf23 | 2020-11-06 18:10:34 | [diff] [blame] | 207 | |
| 208 | ``` |
| 209 | $ tools/android/avd/avd.py start \ |
Haiyang Pan | 56581b3 | 2024-07-03 20:46:40 | [diff] [blame^] | 210 | --avd-config tools/android/avd/proto/android_33_google_apis_x64.textpb \ |
Haiyang Pan | f5faf23 | 2020-11-06 18:10:34 | [diff] [blame] | 211 | --debug-tags init,snapshot |
| 212 | ``` |
| 213 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 214 | ### Using Your Own Emulator Image |
| 215 | |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 216 | By far the easiest way to set up emulator images is to use Android Studio. |
| 217 | If you don't have an [Android Studio project](android_studio.md) already, you |
| 218 | can create a blank one to be able to reach the Virtual Device Manager screen. |
| 219 | |
| 220 | Refer to: https://developer.android.com/studio/run/managing-avds.html |
| 221 | |
| 222 | Where files live: |
| 223 | * System partition images are stored within the sdk directory. |
| 224 | * Emulator configs and data partition images are stored within |
| 225 | `~/.android/avd/`. |
| 226 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 227 | #### Creating an Image |
| 228 | |
| 229 | ##### Choosing a Skin |
| 230 | |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 231 | Choose a skin with a small screen for better performance (unless you care about |
| 232 | testing large screens). |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 233 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 234 | ##### Choosing an Image |
| 235 | |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 236 | Android Studio's image labels roughly translate to the following: |
| 237 | |
Nate Fischer | acbbaab | 2019-04-23 16:46:20 | [diff] [blame] | 238 | | AVD "Target" | Virtual Device Configuration tab | GMS? | Build Properties | |
| 239 | | --- | --- | --- | --- | |
| 240 | | Google Play | "Recommended" (the default tab) | This has GMS | `user`/`release-keys` | |
| 241 | | Google APIs | "x86 Images" | This has GMS | `userdebug`/`dev-keys` | |
| 242 | | No label | "x86 Images" | AOSP image, does not have GMS | `eng`/`test-keys` | |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 243 | |
| 244 | *** promo |
Nate Fischer | acbbaab | 2019-04-23 16:46:20 | [diff] [blame] | 245 | **Tip:** if you're not sure which to use, choose **Google APIs** under the **x86 |
| 246 | Images** tab in the Virtual Device Configuration wizard. |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 247 | *** |
| 248 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 249 | ##### Configuration |
| 250 | |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 251 | "Show Advanced Settings" > scroll down: |
| 252 | * Set internal storage to 4000MB (component builds are really big). |
| 253 | * Set SD card to 1000MB (our tests push a lot of files to /sdcard). |
| 254 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 255 | ##### Known Issues |
| 256 | |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 257 | * Our test & installer scripts do not work with pre-MR1 Jelly Bean. |
| 258 | * Component builds do not work on pre-KitKat (due to the OS having a max |
| 259 | number of shared libraries). |
| 260 | * Jelly Bean and KitKat images sometimes forget to mount /sdcard :(. |
| 261 | * This causes tests to fail. |
| 262 | * To ensure it's there: `adb -s emulator-5554 shell mount` (look for /sdcard) |
| 263 | * Can often be fixed by editing `~/.android/avd/YOUR_DEVICE/config.ini`. |
| 264 | * Look for `hw.sdCard=no` and set it to `yes` |
Nate Fischer | 0dacc46 | 2021-04-06 16:10:24 | [diff] [blame] | 265 | * The "Google APIs" Android L and M emulator images are configured to expect |
| 266 | the "AOSP" WebView package (`com.android.webview`). This does not resemble |
| 267 | production devices with GMS, which expect the ["Google WebView" |
| 268 | configuration](/android_webview/docs/webview-providers.md#webview-provider-options) |
| 269 | (`com.google.android.webview` on L and M). See [Removing preinstalled |
| 270 | WebView](/android_webview/docs/build-instructions.md#Removing-preinstalled-WebView) |
| 271 | if you need to install a local build or official build. |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 272 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 273 | |
| 274 | #### Starting an Emulator from the Command Line |
| 275 | |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 276 | Refer to: https://developer.android.com/studio/run/emulator-commandline.html. |
| 277 | |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 278 | *** promo |
| 279 | Ctrl-C will gracefully close an emulator. |
| 280 | *** |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 281 | |
Nate Fischer | 3680421 | 2020-03-31 02:12:49 | [diff] [blame] | 282 | *** promo |
| 283 | **Tip:** zsh users can add https://github.com/zsh-users/zsh-completions to |
| 284 | provide tab completion for the `emulator` command line tool. |
| 285 | *** |
| 286 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 287 | #### Basic Command Line Use |
| 288 | |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 289 | ```shell |
Andrew Grieve | c8f2703d | 2019-05-22 20:04:44 | [diff] [blame] | 290 | $ # List virtual devices that you've created: |
| 291 | $ ~/Android/Sdk/emulator/emulator -list-avds |
| 292 | $ # Start a named device: |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 293 | $ ~/Android/Sdk/emulator/emulator @EMULATOR_ID |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 294 | ``` |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 295 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 296 | #### Running a Headless Emulator |
| 297 | |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 298 | You can run an emulator without creating a window on your desktop (useful for |
| 299 | `ssh`): |
| 300 | ```shell |
Nate Fischer | 9cbee243 | 2019-04-10 14:51:58 | [diff] [blame] | 301 | $ ~/Android/Sdk/emulator/emulator -no-window @EMULATOR_ID |
Andrew Grieve | c8f2703d | 2019-05-22 20:04:44 | [diff] [blame] | 302 | $ # This also works for new enough emulator builds: |
| 303 | $ ~/Android/Sdk/emulator/emulator-headless @EMULATOR_ID |
| 304 | ``` |
| 305 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 306 | #### Running Multiple Emulators |
| 307 | |
Andrew Grieve | c8f2703d | 2019-05-22 20:04:44 | [diff] [blame] | 308 | Tests are automatically sharded amongst available devices. If you run multiple |
| 309 | emulators, then running test suites becomes much faster. Refer to the |
| 310 | "Multiple AVD instances" section of these [emulator release notes]( |
| 311 | https://androidstudio.googleblog.com/2018/11/emulator-28016-stable.html) |
| 312 | for more about how this works. |
| 313 | ```shell |
Andrew Grieve | c214adb | 2019-05-28 01:39:23 | [diff] [blame] | 314 | $ # Start 8 emulators. Press Ctrl-C to stop them all. |
| 315 | $ ( for i in $(seq 8); do ~/Android/Sdk/emulator/emulator @EMULATOR_ID -read-only & done; wait ) |
Nate Fischer | e44e0f0 | 2019-05-29 20:09:53 | [diff] [blame] | 316 | $ # Start 12 emulators. More than 10 requires disabling audio on some OS's. Reducing cores increases parallelism. |
Andrew Grieve | c214adb | 2019-05-28 01:39:23 | [diff] [blame] | 317 | $ ( for i in $(seq 12); do ~/Android/Sdk/emulator/emulator @EMULATOR_ID -read-only -no-audio -cores 2 & done; wait ) |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 318 | ``` |
| 319 | |
John Budorick | 041a7df | 2020-04-03 23:20:27 | [diff] [blame] | 320 | #### Writable system partition |
| 321 | |
Nate Fischer | 7cbdeae | 2019-01-24 20:29:15 | [diff] [blame] | 322 | Unlike physical devices, an emulator's `/system` partition cannot be modified by |
| 323 | default (even on rooted devices). If you need to do so (such as to remove a |
| 324 | system app), you can start your emulator like so: |
| 325 | ```shell |
| 326 | $ ~/Android/Sdk/emulator/emulator -writable-system @EMULATOR_ID |
| 327 | ``` |
| 328 | |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 329 | ## Using an Emulator |
| 330 | * Emulators show up just like devices via `adb devices` |
| 331 | * Device serials will look like "emulator-5554", "emulator-5556", etc. |
| 332 | |
Nate Fischer | 4a49458 | 2020-03-12 18:08:51 | [diff] [blame] | 333 | ## Emulator pros and cons |
| 334 | |
| 335 | ### Pros |
| 336 | * **Compiles are faster.** Many physical devices are arm64, whereas emulators |
| 337 | are typically x86 (32-bit). 64-bit builds may require 2 copies of the native |
| 338 | library (32-bit and 64-bit), so compiling for an arm64 phone is ~twice as |
| 339 | much work as for an emulator (for targets which support WebView). |
| 340 | * **APKs install faster.** Since emulators run on your workstation, adb can |
| 341 | push the APK onto the emulator without being [bandwidth-constrained by |
| 342 | USB](https://youtu.be/Mzop8bXZI3E). |
| 343 | * Emulators can be nice for working remotely. Physical devices usually require |
| 344 | `scp` or ssh port forwarding to copy the APK from your workstation and |
| 345 | install on a local device. Emulators run on your workstation, so there's **no |
| 346 | ssh slow-down**. |
| 347 | |
| 348 | ### Cons |
| 349 | * If you're investigating a hardware-specific bug report, you'll need a |
| 350 | physical device with the actual hardware to repro that issue. |
| 351 | * x86 emulators need a separate out directory, so building for both physical |
| 352 | devices and emulators takes up more disk space (not a problem if you build |
| 353 | exclusively for the emulator). |
| 354 | * `userdebug`/`eng` emulators don't come with the Play Store installed, so you |
| 355 | can't install third party applications. Sideloading is tricky, as not all |
| 356 | third-party apps support x86. |