Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 1 | # Using an Android Emulator |
| 2 | Always use x86 emulators. Although arm emulators exist, they are so slow that |
| 3 | they are not worth your time. |
| 4 | |
| 5 | ## Building for Emulation |
| 6 | You need to target the correct architecture via GN args: |
| 7 | ``` |
| 8 | target_cpu = "x86" |
| 9 | ``` |
| 10 | |
| 11 | ## Creating an Emulator Image |
| 12 | By far the easiest way to set up emulator images is to use Android Studio. |
| 13 | If you don't have an [Android Studio project](android_studio.md) already, you |
| 14 | can create a blank one to be able to reach the Virtual Device Manager screen. |
| 15 | |
| 16 | Refer to: https://developer.android.com/studio/run/managing-avds.html |
| 17 | |
| 18 | Where 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 | |
| 23 | When creating images: |
| 24 | * Choose a skin with a small screen for better performance (unless you care |
| 25 | about testing large screens). |
| 26 | * Under "Advanced": |
| 27 | * Set internal storage to 4000MB (component builds are really big). |
| 28 | * Set SD card to 1000MB (our tests push a lot of files to /sdcard). |
| 29 | |
| 30 | Known issues: |
| 31 | * Our test & installer scripts do not work with pre-MR1 Jelly Bean. |
| 32 | * Component builds do not work on pre-KitKat (due to the OS having a max |
| 33 | number of shared libraries). |
| 34 | * Jelly Bean and KitKat images sometimes forget to mount /sdcard :(. |
| 35 | * This causes tests to fail. |
| 36 | * To ensure it's there: `adb -s emulator-5554 shell mount` (look for /sdcard) |
| 37 | * Can often be fixed by editing `~/.android/avd/YOUR_DEVICE/config.ini`. |
| 38 | * Look for `hw.sdCard=no` and set it to `yes` |
| 39 | |
Andrew Grieve | a0190fd | 2018-06-15 17:52:49 | [diff] [blame] | 40 | ### Cloning an Image |
| 41 | Running tests on two emulators is twice as fast as running on one. Rather |
| 42 | than use the UI to create additional avds, you can clone an existing one via: |
| 43 | |
| 44 | ```shell |
| 45 | tools/android/emulator/clone_avd.py \ |
| 46 | --source-ini ~/.android/avd/EMULATOR_ID.ini \ |
| 47 | --dest-ini ~/.android/avd/EMULATOR_ID_CLONED.ini \ |
| 48 | --display-name "Cloned Emulator" |
| 49 | ``` |
| 50 | |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 51 | ## Starting an Emulator from the Command Line |
| 52 | Refer to: https://developer.android.com/studio/run/emulator-commandline.html. |
| 53 | |
| 54 | Note: Ctrl-C will gracefully close an emulator. |
| 55 | |
| 56 | If running under remote desktop: |
| 57 | ``` |
| 58 | sudo apt-get install virtualgl |
| 59 | vglrun ~/Android/Sdk/tools/emulator @EMULATOR_ID |
| 60 | ``` |
| 61 | |
| 62 | ## Using an Emulator |
| 63 | * Emulators show up just like devices via `adb devices` |
| 64 | * Device serials will look like "emulator-5554", "emulator-5556", etc. |
| 65 | |