How to speed up Android emulator heavy workflows

Intro

The well-known Start Android emulator step just got updated (1.1.1), and this version now supports waiting for the emulator to boot asynchronously by turning wait_for_boot to false. Beside of updating this step, we’ve created a new step as well: Wait for Android emulator (0.9.0) to be able to validate if the emulator is ready to use or wait for it until it finishes boot.

Why is it so good?

If you set wait_for_boot option to false, that makes it possible to start your Android emulator at the beginning of your workflow and run couple of steps while the emulator is booting, this way you can save time doing multiple tasks at the same time.

I already have a workflow that uses Android emulator, so what?

  • Move Create Android emulator and Start Android emulator steps at one of the first places of your workflow and set the wait_for_boot option (of the Start Android emulator step) to false.
  • Run as many steps as you wish, emulator booting will be done in the background :ok_hand:
  • Add Wait for Android emulator step before the step which requires a booted/running Android emulator, so it will check if the emulator is ready to use, or will wait until it finishes boot and then continues your workflow

An example bitrise.yml:

---
format_version: 1.3.1
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
trigger_map:
- push_branch: "*"
  workflow: WaitStepExample
- pull_request_source_branch: "*"
  workflow: WaitStepExample
workflows:
  WaitStepExample:
    steps:
    - create-android-emulator:
        inputs:
        - name: android-24-armeabi-v7a
    - start-android-emulator:
        inputs:
        - wait_for_boot: 'false'
    - git-clone@3.4.1: {}
    - activate-ssh-key@3.1.1:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - nuget-restore@1.0.3: {}
    - xamarin-archive@1.3.1:
        inputs:
        - project_type_whitelist: android
    - wait-for-android-emulator@0.9.0: {}
    - calabash-android-uitest:
        inputs:
        - work_dir: Droid
    before_run: 
    after_run: 
app:
  envs:
  - opts:
      is_expand: false
    BITRISE_PROJECT_PATH: Multiplatform.sln
  - opts:
      is_expand: false
    BITRISE_XAMARIN_CONFIGURATION: calabash
  - opts:
      is_expand: false
    BITRISE_XAMARIN_PLATFORM: Any CPU

###Saving time
We’ve run couple of tests, and workflow runtimes decreased an average ~1-3 minutes. In the tests we’ve used the workflow above, and see the results below.

  • With Wait for Android emulator step:
+------------------------------------------------------------------------------+
|                               bitrise summary                                |
+---+---------------------------------------------------------------+----------+
|   | title                                                         | time (s) |
+---+---------------------------------------------------------------+----------+
| ✓ | create-android-emulator                                       | 22 sec   |
+---+---------------------------------------------------------------+----------+
| ✓ | start-android-emulator                                        | 48 sec   |
+---+---------------------------------------------------------------+----------+
| ✓ | git-clone@3.4.1                                               | 7.68 sec |
+---+---------------------------------------------------------------+----------+
| ✓ | nuget-restore@1.0.3                                           | 27 sec   |
+---+---------------------------------------------------------------+----------+
| ✓ | script@1.1.3                                                  | 183 sec  |
+---+---------------------------------------------------------------+----------+
| ✓ | xamarin-archive@1.3.1                                         | 31 sec   |
+---+---------------------------------------------------------------+----------+
| ✓ | wait-for-android-emulator@0.9.0                               | 9.66 sec |
+---+---------------------------------------------------------------+----------+
| ✓ | calabash-android-uitest                                       | 103 sec  |
+---+---------------------------------------------------------------+----------+
| Total runtime: 432 sec                                                       |
+------------------------------------------------------------------------------+
  • Without Wait for Android emulator step:
+------------------------------------------------------------------------------+
|                               bitrise summary                                |
+---+---------------------------------------------------------------+----------+
|   | title                                                         | time (s) |
+---+---------------------------------------------------------------+----------+
| ✓ | create-android-emulator                                       | 23 sec   |
+---+---------------------------------------------------------------+----------+
| ✓ | start-android-emulator                                        | 193 sec  |
+---+---------------------------------------------------------------+----------+
| ✓ | git-clone@3.4.1                                               | 5.26 sec |
+---+---------------------------------------------------------------+----------+
| ✓ | nuget-restore@1.0.3                                           | 28 sec   |
+---+---------------------------------------------------------------+----------+
| ✓ | script@1.1.3                                                  | 184 sec  |
+---+---------------------------------------------------------------+----------+
| ✓ | xamarin-archive@1.3.1                                         | 30 sec   |
+---+---------------------------------------------------------------+----------+
| ✓ | calabash-android-uitest                                       | 118 sec  |
+---+---------------------------------------------------------------+----------+
| Total runtime: 581 sec                                                       |
+------------------------------------------------------------------------------+
3 Likes