1. circleci/android@3.0.2

circleci/android@3.0.2

Certified
Sections
Orb for working with Android projects on CircleCI. Supports running Android emulator UI tests.
Created: February 21, 2019Version Published: November 15, 2024Releases: 24
Org Usage:
1002
Categories:

Orb Quick Start Guide

Use CircleCI version 2.1 at the top of your .circleci/config.yml file.

1 version: 2.1

Add the orbs stanza below your version, invoking the orb:

1 2 orbs: android: circleci/android@3.0.2

Use android elements in your existing workflows and jobs.

Usage Examples

granular_commands

An example of using the more granular commands of the orb together, to achieve something similar to using the "start_emulator_and_run_tests" command or the "run_ui_tests" job.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 version: '2.1' orbs: android: circleci/android@3.0.0 jobs: test: executor: name: android/android_machine resource_class: large tag: default steps: - checkout - android/create_avd: avd_name: myavd install: true system_image: system-images;android-31;default;x86_64 - android/start_emulator: avd_name: myavd no_window: true restore_gradle_cache_prefix: v1a - android/run_tests - android/save_gradle_cache: cache_prefix: v1a workflows: test: jobs: - test

override_machine_resource_class

An example of overriding the android_machine executor's default resource class

1 2 3 4 5 6 7 8 9 10 11 version: '2.1' orbs: android: circleci/android@3.0.0 workflows: test: jobs: - android/run_ui_tests: executor: name: android/android_machine resource_class: xlarge tag: default

run_ui_tests_job

A simple example of using the run_ui_tests job, using most of the default parameters. Parameters like the system_image and emulator options (e.g. "no_window") may need to be adjusted from the defaults, according to your project.

1 2 3 4 5 6 7 8 9 10 11 12 version: '2.1' orbs: android: circleci/android@3.0.0 workflows: test: jobs: - android/run_ui_tests: executor: name: android/android_machine resource-class: large tag: 2024.01.1 system_image: system-images;android-31;default;x86_64

start_emulator_and_run_tests

A simple example of using the start_emulator_and_run_tests command in a job, using most of the default parameters. Parameters like the system_image and emulator options (e.g. "no_window") may need to be adjusted from the defaults, according to your project.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 version: '2.1' orbs: android: circleci/android@3.0.0 jobs: test: executor: name: android/android_machine resource_class: large tag: default steps: - checkout - android/start_emulator_and_run_tests: system_image: system-images;android-31;default;x86_64 workflows: test: jobs: - test

test_matrix

A simple example of using a test matrix to test on different emulators.

1 2 3 4 5 6 7 8 9 10 11 12 13 version: '2.1' orbs: android: circleci/android@3.0.0 workflows: test: jobs: - android/run_ui_tests: matrix: parameters: system_image: - system-images;android-31;default;x86_64 - system-images;android-31;default;x86_64 name: ui-tests-<<matrix.system_image>>

Jobs

build

Start building an Android project on CircleCI

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
executor
Executor for the job
Yes
-
executor

deploy_to_play_store

Deploy an android app on CircleCI to the Google Play Store using Fastlane. For use with CirceCI Environment Variables.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
base64_keystore
Your base64 keystore
No
BASE64_KEYSTORE
env_var_name
checkout
Whether to run the checkout step
No
true
boolean
executor
Executor for the job
Yes
-
executor
fastlane_working_directory
Working directory to run fastlane commands in
No
.
string
google_play_key
Your google play key
No
GOOGLE_PLAY_KEY
env_var_name
keystore_location
The location of your decrypted keystore
No
.
string
keystore_properties_working_directory
Working directory to create keystore.properties in
No
.
string
lane_name
The name of the lane fastlane will execute
No
deploy
string
release_key_alias
Release key alias
No
RELEASE_KEY_ALIAS
env_var_name
release_key_password
Password for your release key
No
RELEASE_KEY_PASSWORD
env_var_name
release_keystore
Points to the location of your decrypted keystore
No
./keystore
string
release_store_password
Password for your keystore
No
RELEASE_STORE_PASSWORD
env_var_name

run_ui_tests

Creates an AVD, starts an emulator and runs Android UI tests. This is a job that wraps the "start_emulator_and_run_tests" command.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_avd_args
Additional args to be passed directly to the avd creation command
No
''
string
additional_emulator_args
Additional args to be passed directly to the emulator command
No
''
string
avd_name
The name of the AVD to create
No
test
string
camera_back
The value to use for the "-camera-back" flag. If set to "", the emulator will be run without the -camera-back flag.
No
''
string
camera_front
The value to use for the "-camera-front" flag. If set to "", the emulator will be run without the -camera-front flag.
No
''
string
checkout
Whether to run the checkout step
No
true
boolean
delay_adb
Whether to run the emulator with the -delay-adb flag
No
false
boolean
disable_animations
Whether to disable animations that may interfere with tests, after the emulator starts up
No
true
boolean
executor
Executor for the job
Yes
-
executor
gpu
The value to use for the "-gpu" flag. If set to "", the emulator will be run without the -gpu flag.
No
swiftshader_indirect
string
install_system_image
Whether to first install the system image via sdkmanager
No
true
boolean
kill_emulators
Whether to kill the emulators after the tests complete
No
true
boolean
max_tries
Max number of tries. To disable retries, set this to 1.
No
2
integer
memory
The value to use for the "-memory" flag. If set to -1, the emulator will be run without the -memory flag.
No
-1
integer
no_audio
Whether to run the emulator with the -noaudio flag
No
true
boolean
no_boot_anim
Whether to run the emulator with the -no-boot-anim flag
No
true
boolean
no_output_timeout
Use this to configure the no_output_timeout value of the test run
No
10m
string
no_snapshot
Whether to run the emulator with the -no-snapshot flag
No
true
boolean
no_window
Whether to run the emulator with the -no-window flag
No
true
boolean
override_emulator_args
If this is set to a non-blank value, the emulator command will be run with the -avd flag and the value of "override_args" (i.e. none of the defaults provided by the orb command will be used)
No
''
string
post_emulator_launch_assemble_command
If this is set to a non-blank value, the configured command will be run after the emulator has been launched, and before commencing the wait for the emulator to finish starting up.
No
./gradlew assembleDebugAndroidTest
string
post_emulator_wait_steps
Steps to execute after waiting for the emulator to start up
No
[]
steps
post_run_tests_steps
Steps to run after the tests
No
[]
steps
pre_emulator_wait_steps
Steps to execute while before beginning to wait for the emulator to start up
No
[]
steps
pre_run_tests_steps
Steps to run before the tests
No
[]
steps
pre_test_command
Command to run prior to runnning the test command
No
' '
string
pull_data
Whether to pull data after running tests
No
false
boolean
pull_data_path
Emulator directory to pull data from
No
data
string
pull_data_target
Location to save pulled data
No
.
string
restore_gradle_cache_find_args
Use this to customize how the find command is used to look for relevant file changes.
No
. -name "build.gradle*" -o -name "settings.gradle*"
string
restore_gradle_cache_post_emulator_launch
Whether to restore the gradle cache after the emulator has been launched, and before commencing the wait for the emulator to finish starting up.
No
true
boolean
restore_gradle_cache_prefix
Cache prefix used if the "restore_gradle_cache_post_emulator_launch" parameter is set to true.
No
v1
string
retry_interval
Duration in seconds to wait before the next try
No
5
integer
run_logcat
Whether to run with logcat in the background, after the emulator starts up
No
false
boolean
run_tests_working_directory
Working directory to run the tests in
No
.
string
save_gradle_cache
Whether to write to the gradle cache after the tests have run
No
true
boolean
system_image
Name of system image e.g. "system-images;android-29;default;x86". It should match the name seen in the "sdkmanager --list" output.
No
system-images;android-29;default;x86
string
test_command
Command to run in order to run the tests
No
./gradlew connectedDebugAndroidTest
string
verbose
Whether to run the emulator with the -verbose flag
No
true
boolean
wait_for_emulator
Whether to wait for the emulator to start up
No
true
boolean

Commands

accept_licenses

Accept all Android SDK Manager licenses

Show command Source

change_java_version

Change default java version from OpenJDK v17.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
java_version
The version of OpenJDK to change to
No
8
integer

change_malloc

Change default malloc from glibc malloc to jemalloc

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
implementation
-
No
jemalloc
enum

create_avd

Create an AVD.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_args
Additional args to be passed directly to the avd creation command You can pass environment variables, using the $ syntax e.g. "$ADDITIONAL_ARGS"
No
''
string
avd_name
The name of the AVD to create. You can pass environment variables, using the $ syntax e.g. "$AVD_NAME"
Yes
-
string
background
Whether to run the creation command in background
No
false
boolean
install
Whether to first install the system image via sdkmanager
Yes
-
boolean
system_image
Name of system image e.g. "system-images;android-29;default;x86". It should match the name seen in the "sdkmanager --list" output. You can pass environment variables, using the $ syntax e.g. "$SYSTEM_IMAGE"
Yes
-
string

create_google_play_key

Generate JSON file for your google play key. For use with environment variables.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
google_play_key
Your google play key
No
GOOGLE_PLAY_KEY
env_var_name
working_directory
Working directory to create google play key in
No
.
string

create_keystore_properties

Creates a keystore.properties file for use in deployment steps. For use with environment variables.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
release_key_alias
Release key alias
No
RELEASE_KEY_ALIAS
env_var_name
release_key_password
Password for your release key
No
RELEASE_KEY_PASSWORD
env_var_name
release_keystore
Points to the location of your decrypted keystore
No
./keystore
string
release_store_password
Password for your keystore
No
RELEASE_STORE_PASSWORD
env_var_name
working_directory
Working directory to create keystore.properties in
No
.
string

decode_keystore

Decodes a keystore that was encrypted in base64. For use with environment variables.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
base64_keystore
Your base64 keystore
No
BASE64_KEYSTORE
env_var_name
keystore_location
The location of your decrypted keystore
No
.
string

disable_animations

Disables animations. Requires an emulator to be running.

Show command Source

fastlane_deploy

Runs fastlane lanes to deploy to Google Play Store

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
lane_name
The name of the lane fastlane will execute
No
deploy
string
working_directory
Working directory to run fastlane commands in
No
.
string

install_ndk

Install an Android NDK version using 'sdkmanager'. This command takes one parameter called 'ndk', which is the NDK version. If the version is already available, the step will still complete successfully. This command is designed to be used with the CircleCI Android Docker or machine images. Available NDK versions can be found here: https://github.com/android/compose-samples

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
version
Version of the NDK to install. Available NDK versions can be found here: https://github.com/android/compose-samples
Yes
-
string

kill_emulators

Terminates any running emulator processes

Show command Source

restore_build_cache

Restore the build cache. See `save_build_cache` for more information.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_prefix
Used to form part of the cache key
No
v1
string

restore_gradle_cache

Restore gradle cache

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_prefix
Used to form part of the cache key
No
v1
string
find_args
Use this to customize how the find command is used to look for relevant file changes.
No
. -name "build.gradle*" -o -name "settings.gradle*"
string

run_tests

Runs tests, with retries supported

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
max_tries
Max number of tries. To disable retries, set this to 1.
No
2
integer
no_output_timeout
Use this to configure the no_output_timeout value
No
10m
string
pre_test_command
Command to run prior to runnning the test command You can pass environment variables, using the $ syntax e.g. "$PRE_TEST_COMMAND"
No
' '
string
pull_data
Whether to pull data after running tests
No
false
boolean
pull_data_path
Emulator directory to pull data from
No
data
string
pull_data_target
Location to save pulled data
No
.
string
retry_interval
Duration in seconds to wait before the next try
No
5
integer
test_command
Command to run in order to run the tests You can pass environment variables, using the $ syntax e.g. "$TEST_COMMAND"
No
./gradlew connectedDebugAndroidTest
string
working_directory
Working directory to run the tests in
No
.
string

save_build_cache

Save the Android build-cache. The build cache stores certain outputs that the Android plugin for Gradle generates when building your project (such as unpackaged AARs and pre-dexed remote dependencies). Your clean builds are much faster while using the cache because the build system can simply reuse those cached files during subsequent builds, instead of recreating them. The build cache also works on continuous integration servers and when running multiple build processes on a single local machine. See https://developer.android.com/studio/build/build-cache

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_prefix
Used to form part of the cache key
No
v1
string

save_gradle_cache

Save gradle cache

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_prefix
Used to form part of the cache key
No
v1
string

start_emulator

Start an emulator as a background process. The AVD used should already be created. (See "create_avd" command for how one could be created)

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_args
Additional args to be passed directly to the emulator command
No
''
string
avd_name
The name of the existing AVD to use for the emulator
Yes
-
string
camera_back
The value to use for the "-camera-back" flag. If set to "", the emulator will be run without the -camera-back flag.
No
''
string
camera_front
The value to use for the "-camera-front" flag. If set to "", the emulator will be run without the -camera-front flag.
No
''
string
delay_adb
Whether to run the emulator with the -delay-adb flag
No
false
boolean
disable_animations
Whether to disable animations that may interfere with tests, after the emulator starts up
No
true
boolean
gpu
The value to use for the "-gpu" flag. If set to "", the emulator will be run without the -gpu flag.
No
swiftshader_indirect
string
memory
The value to use for the "-memory" flag. If set to -1, the emulator will be run without the -memory flag.
No
-1
integer
no_audio
Whether to run the emulator with the -noaudio flag
No
true
boolean
no_boot_anim
Whether to run the emulator with the -no-boot-anim flag
No
true
boolean
no_snapshot
Whether to run the emulator with the -no-snapshot flag
No
true
boolean
no_window
Whether to run the emulator with the -no-window flag
No
true
boolean
override_args
If this is set to a non-blank value, the emulator command will be run with the -avd flag and the value of "override_args" (i.e. none of the defaults provided by the orb command will be used)
No
''
string
post_emulator_launch_assemble_command
If this is set to a non-blank value, the configured command will be run after the emulator has been launched, and before commencing the wait for the emulator to finish starting up.
No
./gradlew assembleDebugAndroidTest
string
post_emulator_wait_steps
Steps to execute after waiting for the emulator to start up
No
[]
steps
pre_emulator_wait_steps
Steps to execute while before beginning to wait for the emulator to start up
No
[]
steps
restore_gradle_cache_find_args
Use this to customize how the find command is used to look for relevant file changes.
No
. -name "build.gradle*" -o -name "settings.gradle*"
string
restore_gradle_cache_post_emulator_launch
Whether to restore the gradle cache after the emulator has been launched, and before commencing the wait for the emulator to finish starting up.
No
true
boolean
restore_gradle_cache_prefix
Cache prefix used if the "restore_gradle_cache_post_emulator_launch" parameter is set to true.
No
v1
string
run_logcat
Whether to run with logcat in the background, after the emulator starts up
No
false
boolean
verbose
Whether to run the emulator with the -verbose flag
No
true
boolean
wait_for_emulator
Whether to wait for the emulator to start up
No
true
boolean

start_emulator_and_run_tests

Creates an AVD, starts an emulator and runs tests. This is a wrapper command that wraps the create_avd, start_emulator and run_tests commands.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_avd_args
Additional args to be passed directly to the avd creation command. You can pass environment variables, using the $ syntax e.g. "$ADDITIONAL_ARGS"
No
''
string
additional_emulator_args
Additional args to be passed directly to the emulator command
No
''
string
avd_name
The name of the AVD to create. You can pass environment variables, using the $ syntax e.g. "$AVD_NAME"
No
test
string
camera_back
The value to use for the "-camera-back" flag. If set to "", the emulator will be run without the -camera-back flag.
No
''
string
camera_front
The value to use for the "-camera-front" flag. If set to "", the emulator will be run without the -camera-front flag.
No
''
string
delay_adb
Whether to run the emulator with the -delay-adb flag
No
false
boolean
disable_animations
Whether to disable animations that may interfere with tests, after the emulator starts up
No
true
boolean
gpu
The value to use for the "-gpu" flag. If set to "", the emulator will be run without the -gpu flag.
No
swiftshader_indirect
string
install_system_image
Whether to first install the system image via sdkmanager
No
true
boolean
kill_emulators
Whether to kill the emulators after the tests complete
No
true
boolean
max_tries
Max number of tries. To disable retries, set this to 1.
No
2
integer
memory
The value to use for the "-memory" flag. If set to -1, the emulator will be run without the -memory flag.
No
-1
integer
no_audio
Whether to run the emulator with the -noaudio flag
No
true
boolean
no_boot_anim
Whether to run the emulator with the -no-boot-anim flag
No
true
boolean
no_output_timeout
Use this to configure the no_output_timeout value of the test run
No
10m
string
no_snapshot
Whether to run the emulator with the -no-snapshot flag
No
true
boolean
no_window
Whether to run the emulator with the -no-window flag
No
true
boolean
override_emulator_args
If this is set to a non-blank value, the emulator command will be run with the -avd flag and the value of "override_args" (i.e. none of the defaults provided by the orb command will be used)
No
''
string
post_emulator_launch_assemble_command
If this is set to a non-blank value, the configured command will be run after the emulator has been launched, and before commencing the wait for the emulator to finish starting up.
No
./gradlew assembleDebugAndroidTest
string
post_emulator_wait_steps
Steps to execute after waiting for the emulator to start up
No
[]
steps
post_run_tests_steps
Steps to run after the tests
No
[]
steps
pre_emulator_wait_steps
Steps to execute while before beginning to wait for the emulator to start up
No
[]
steps
pre_run_tests_steps
Steps to run before the tests
No
[]
steps
pre_test_command
Command to run prior to runnning the test command You can pass environment variables, using the $ syntax e.g. "$PRE_TEST_COMMAND"
No
' '
string
pull_data
Whether to pull data after running tests
No
false
boolean
pull_data_path
Emulator directory to pull data from
No
data
string
pull_data_target
Location to save pulled data
No
.
string
restore_gradle_cache_find_args
Use this to customize how the find command is used to look for relevant file changes.
No
. -name "build.gradle*" -o -name "settings.gradle*"
string
restore_gradle_cache_post_emulator_launch
Whether to restore the gradle cache after the emulator has been launched, and before commencing the wait for the emulator to finish starting up.
No
true
boolean
restore_gradle_cache_prefix
Cache prefix used if the "restore_gradle_cache_post_emulator_launch" parameter is set to true.
No
v1
string
retry_interval
Duration in seconds to wait before the next try
No
5
integer
run_logcat
Whether to run with logcat in the background, after the emulator starts up
No
false
boolean
run_tests_working_directory
Working directory to run the tests in
No
.
string
save_gradle_cache
Whether to write to the gradle cache after the tests have run
No
true
boolean
system_image
Name of system image e.g. "system-images;android-29;default;x86". It should match the name seen in the "sdkmanager --list" output. You can pass environment variables, using the $ syntax e.g. "$SYSTEM_IMAGE"
No
system-images;android-29;default;x86
string
test_command
Command to run in order to run the tests You can pass environment variables, using the $ syntax e.g. "$TEST_COMMAND"
No
./gradlew connectedDebugAndroidTest
string
verbose
Whether to run the emulator with the -verbose flag
No
true
boolean
wait_for_emulator
Whether to wait for the emulator to start up
No
true
boolean

wait_for_emulator

Wait for the emulator to start. Requires the "circle-android" script to be present in PATH.

Show command Source

Executors

android_docker

Select a CircleCI convenience image to get building on Android. See https://circleci.com/developer/images/image/cimg/android#image-tags for a full list of the available images.

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
resource_class
Resource class used for the executor.
No
medium
enum
tag
The Android image tag to use. Choose a tag from https://circleci.com/developer/images/image/cimg/android#image-tags.
Yes
-
string

android_machine

This selects an Android machine image. CircleCI's Android machine images are recommended for Android emulator tests.

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
resource_class
Resource class used for the executor. It is recommended to use large and above to avoid memory issues such as process crashes when running emulator tests.
No
large
enum
tag
Name of CircleCI Android machine image to use. Android machine tags can be found at https://circleci.com/developer/machine/image/android#image-tags
Yes
-
string

Orb Source

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 # This code is licensed from CircleCI to the user under the MIT license. # See here for details: https://circleci.com/developer/orbs/licensing version: 2.1 description: | Orb for working with Android projects on CircleCI. Supports running Android emulator UI tests. display: source_url: https://github.com/circleci-public/android-orb commands: accept_licenses: description: | Accept all Android SDK Manager licenses steps: - run: command: | yes | sdkmanager --licenses yes | sdkmanager --update description: | Accepts all Android SDK licenses. This command is typically not necessary to execute, since the CircleCI machine/convenience images ship with all licenses accepted. This command will add approximately 10 seconds to the build time. name: Accept Android Licenses shell: /bin/bash -e change_java_version: description: | Change default java version from OpenJDK v17. parameters: java_version: default: 8 description: | The version of OpenJDK to change to type: integer steps: - run: command: | #!/bin/bash CURRENT_JAVA_VER="$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)" CURRENT_JAVAC_VER="$(javac -version 2>&1 | head -1 | cut -f 2- -d ' ' | sed '/^1\./s///' | cut -d'.' -f1)" echo "Current Java Version: $CURRENT_JAVA_VER" echo "Current Java Compiler Version : $CURRENT_JAVAC_VER" if [ "$CURRENT_JAVA_VER" -ne "${PARAM_JAVA_VER}" ]; then if [ "${PARAM_JAVA_VER}" -eq 8 ] || [ "${PARAM_JAVA_VER}" -eq 17 ]; then if [ "${PARAM_JAVA_VER}" -eq 8 ]; then sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java else sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java fi sudo update-alternatives --set javac /usr/lib/jvm/java-"${PARAM_JAVA_VER}"-openjdk-amd64/bin/javac else sudo apt-get update sudo apt install openjdk-"${PARAM_JAVA_VER}"-jdk sudo update-alternatives --set javac /usr/lib/jvm/java-"${PARAM_JAVA_VER}"-openjdk-amd64/bin/javac sudo update-alternatives --set java /usr/lib/jvm/java-"${PARAM_JAVA_VER}"-openjdk-amd64/bin/java fi echo "export JAVA_HOME=/usr/lib/jvm/java-${PARAM_JAVA_VER}-openjdk-amd64" >> "$BASH_ENV" echo "export PATH=\$JAVA_HOME/bin:\$PATH" >> "$BASH_ENV" fi NEW_JAVA_VER="$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)" NEW_JAVAC_VER="$(javac -version 2>&1 | head -1 | cut -f 2- -d ' ' | sed '/^1\./s///' | cut -d'.' -f1)" echo "New Java Version : $NEW_JAVA_VER" echo "New Java Compiler Version : $NEW_JAVAC_VER" environment: PARAM_JAVA_VER: << parameters.java_version >> name: Change OpenJDK version to << parameters.java_version >> change_malloc: description: | Change default malloc from glibc malloc to jemalloc parameters: implementation: default: jemalloc enum: - jemalloc - tcmalloc type: enum steps: - run: command: | #!/bin/bash sudo apt update if [[ ${PARAM_IMPLEMENTATION} == "jemalloc" ]]; then sudo apt install libjemalloc-dev echo "LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2" | sudo tee -a /etc/environment else sudo apt install google-perftools echo "LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4" | sudo tee -a /etc/environment fi environment: PARAM_IMPLEMENTATION: << parameters.implementation >> name: change malloc implementation to << parameters.implementation >> create_avd: description: | Create an AVD. parameters: additional_args: default: "" description: | Additional args to be passed directly to the avd creation command You can pass environment variables, using the $ syntax e.g. "$ADDITIONAL_ARGS" type: string avd_name: description: | The name of the AVD to create. You can pass environment variables, using the $ syntax e.g. "$AVD_NAME" type: string background: default: false description: | Whether to run the creation command in background type: boolean install: description: | Whether to first install the system image via sdkmanager type: boolean system_image: description: | Name of system image e.g. "system-images;android-29;default;x86". It should match the name seen in the "sdkmanager --list" output. You can pass environment variables, using the $ syntax e.g. "$SYSTEM_IMAGE" type: string steps: - run: background: << parameters.background >> command: | #!/bin/bash PARAM_AVD_NAME="$(echo "$PARAM_AVD_NAME" | circleci env subst "$PARAM_AVD_NAME")" PARAM_SYSTEM_IMAGE="$(echo "$PARAM_SYSTEM_IMAGE" | circleci env subst "$PARAM_SYSTEM_IMAGE")" PARAM_ADDITIONAL_ARGS="$(circleci env subst -- "$PARAM_ADDITIONAL_ARGS")" if [ "${PARAM_INSTALL}" == 1 ]; then sdkmanager "${PARAM_SYSTEM_IMAGE}" fi echo "no" | avdmanager --verbose create avd -n ${PARAM_AVD_NAME} -k ${PARAM_SYSTEM_IMAGE} ${PARAM_ADDITIONAL_ARGS} environment: PARAM_ADDITIONAL_ARGS: << parameters.additional_args >> PARAM_AVD_NAME: << parameters.avd_name >> PARAM_INSTALL: << parameters.install >> PARAM_SYSTEM_IMAGE: << parameters.system_image >> name: Create avd "<< parameters.avd_name >>" create_google_play_key: description: | Generate JSON file for your google play key. For use with environment variables. parameters: google_play_key: default: GOOGLE_PLAY_KEY description: Your google play key type: env_var_name working_directory: default: . description: Working directory to create google play key in type: string steps: - run: command: echo ${<< parameters.google_play_key >>} > google-play-key.json name: Create Google Play key working_directory: << parameters.working_directory >> create_keystore_properties: description: | Creates a keystore.properties file for use in deployment steps. For use with environment variables. parameters: release_key_alias: default: RELEASE_KEY_ALIAS description: Release key alias type: env_var_name release_key_password: default: RELEASE_KEY_PASSWORD description: Password for your release key type: env_var_name release_keystore: default: ./keystore description: Points to the location of your decrypted keystore type: string release_store_password: default: RELEASE_STORE_PASSWORD description: Password for your keystore type: env_var_name working_directory: default: . description: Working directory to create keystore.properties in type: string steps: - run: command: |- #!/bin/bash # RELEASE_KEY_ALIAS=$(eval echo "\$$PARAM_RELEASE_KEY_ALIAS") # RELEASE_KEY_PASSWORD=$(eval echo "\$$PARAM_RELEASE_KEY_PASSWORD") # RELEASE_STORE_PASSWORD=$(eval echo "\$$PARAM_RELEASE_STORE_PASSWORD") RELEASE_KEY_ALIAS="${!PARAM_RELEASE_KEY_ALIAS}" RELEASE_KEY_PASSWORD="${!PARAM_RELEASE_KEY_PASSWORD}" RELEASE_STORE_PASSWORD="${!PARAM_RELEASE_STORE_PASSWORD}" printf 'releaseKeyAlias=%s\nreleaseKeyPassword=%s\nreleaseKeyStore=%s\nreleaseStorePassword=%s' \ "$RELEASE_KEY_ALIAS" "$RELEASE_KEY_PASSWORD" "${PARAM_RELEASE_KEYSTORE}" "$RELEASE_STORE_PASSWORD" > keystore.properties environment: PARAM_RELEASE_KEY_ALIAS: << parameters.release_key_alias >> PARAM_RELEASE_KEY_PASSWORD: << parameters.release_key_password >> PARAM_RELEASE_KEYSTORE: << parameters.release_keystore >> PARAM_RELEASE_STORE_PASSWORD: << parameters.release_store_password >> name: Create keystore.properties working_directory: << parameters.working_directory >> decode_keystore: description: | Decodes a keystore that was encrypted in base64. For use with environment variables. parameters: base64_keystore: default: BASE64_KEYSTORE description: Your base64 keystore type: env_var_name keystore_location: default: . description: The location of your decrypted keystore type: string steps: - run: command: | #!/bin/bash PARAM_BASE64_KEYSTORE=$(eval echo "\$$PARAM_BASE64_KEYSTORE") echo "$PARAM_BASE64_KEYSTORE" | base64 -di | tee keystore "${PARAM_KEYSTORE_LOCATION}" > /dev/null environment: PARAM_BASE64_KEYSTORE: << parameters.base64_keystore >> PARAM_KEYSTORE_LOCATION: << parameters.keystore_location >> name: Decode Keystore disable_animations: description: | Disables animations. Requires an emulator to be running. steps: - run: command: |- #!/bin/bash adb shell settings put global window_animation_scale 0.0 adb shell settings put global transition_animation_scale 0.0 adb shell settings put global animator_duration_scale 0.0 name: Disable emulator animations fastlane_deploy: description: | Runs fastlane lanes to deploy to Google Play Store parameters: lane_name: default: deploy description: The name of the lane fastlane will execute type: string working_directory: default: . description: Working directory to run fastlane commands in type: string steps: - run: command: fastlane << parameters.lane_name >> name: Run fastlane working_directory: << parameters.working_directory >> install_ndk: description: | Install an Android NDK version using 'sdkmanager'. This command takes one parameter called 'ndk', which is the NDK version. If the version is already available, the step will still complete successfully. This command is designed to be used with the CircleCI Android Docker or machine images. Available NDK versions can be found here: https://github.com/android/compose-samples parameters: version: description: | Version of the NDK to install. Available NDK versions can be found here: https://github.com/android/compose-samples type: string steps: - run: command: |- #!/bin/bash echo y | sdkmanager "ndk;${PARAM_VER}" android_ndk_home="" if [[ -d "${HOME}/android-sdk/ndk/${PARAM_VER}" ]]; then android_ndk_home="$HOME/android-sdk/ndk/${PARAM_VER}" elif [[ -d "/opt/android/sdk/ndk/${PARAM_VER}" ]]; then android_ndk_home="/opt/android/sdk/ndk/${PARAM_VER}" else echo "Android NDK did not install successfully" exit 1 fi echo "export ANDROID_NDK_HOME=$android_ndk_home" >> "$BASH_ENV" echo "Android NDK was installed at \"$android_ndk_home\"." environment: PARAM_VER: << parameters.version >> name: Install Android NDK kill_emulators: description: | Terminates any running emulator processes steps: - run: command: |- #!/bin/bash # shellcheck disable=SC2154 adb devices | grep emulator | cut -f1 | while read -r line; do adb -s $line emu kill; done name: Kill any running emulators restore_build_cache: description: | Restore the build cache. See `save_build_cache` for more information. parameters: cache_prefix: default: v1 description: Used to form part of the cache key type: string steps: - restore_cache: key: android-orb-<<parameters.cache_prefix>> name: Restore build cache restore_gradle_cache: description: | Restore gradle cache parameters: cache_prefix: default: v1 description: Used to form part of the cache key type: string find_args: default: . -name "build.gradle*" -o -name "settings.gradle*" description: | Use this to customize how the find command is used to look for relevant file changes. type: string steps: - run: command: "#!/bin/bash\necho \"The following are the files used to generate the cache checksum:\"\neval find \"${PARAM_FIND_ARGS}\"\neval find \"${PARAM_FIND_ARGS}\" | sort | xargs cat |\nshasum | awk '{print $1}' > /tmp/gradle_cache_seed \n" environment: PARAM_FIND_ARGS: << parameters.find_args >> name: Generate cache checksum - restore_cache: key: gradle-<< parameters.cache_prefix>>-{{ arch }}-{{ checksum "/tmp/gradle_cache_seed" }} name: Restore gradle cache run_tests: description: | Runs tests, with retries supported parameters: max_tries: default: 2 description: Max number of tries. To disable retries, set this to 1. type: integer no_output_timeout: default: 10m description: Use this to configure the no_output_timeout value type: string pre_test_command: default: ' ' description: | Command to run prior to runnning the test command You can pass environment variables, using the $ syntax e.g. "$PRE_TEST_COMMAND" type: string pull_data: default: false description: | Whether to pull data after running tests type: boolean pull_data_path: default: data description: | Emulator directory to pull data from type: string pull_data_target: default: . description: | Location to save pulled data type: string retry_interval: default: 5 description: Duration in seconds to wait before the next try type: integer test_command: default: ./gradlew connectedDebugAndroidTest description: | Command to run in order to run the tests You can pass environment variables, using the $ syntax e.g. "$TEST_COMMAND" type: string working_directory: default: . description: Working directory to run the tests in type: string steps: - run: command: | #!/bin/bash PARAM_PRE_TEST_COMMAND="$(echo "$PARAM_PRE_TEST_COMMAND" | circleci env subst "$PARAM_PRE_TEST_COMMAND")" PARAM_TEST_COMMAND="$(echo "$PARAM_TEST_COMMAND" | circleci env subst "$PARAM_TEST_COMMAND")" run_with_retry() { MAX_TRIES=${PARAM_MAX_TRIES} n=1 until [ $n -gt $MAX_TRIES ]; do echo "Starting test attempt $n" eval "${PARAM_PRE_TEST_COMMAND}" eval "${PARAM_TEST_COMMAND}" && break n=$((n + 1)) sleep "${PARAM_RETRY_INTERVAL}" done if [ $n -gt $MAX_TRIES ]; then echo "Max tries reached (${PARAM_MAX_TRIES})" exit 1 fi } run_with_retry environment: PARAM_MAX_TRIES: << parameters.max_tries >> PARAM_PRE_TEST_COMMAND: << parameters.pre_test_command >> PARAM_RETRY_INTERVAL: << parameters.retry_interval >> PARAM_TEST_COMMAND: << parameters.test_command >> name: Run tests with max tries of <<parameters.max_tries>> no_output_timeout: <<parameters.no_output_timeout>> working_directory: <<parameters.working_directory>> - when: condition: << parameters.pull_data >> steps: - run: adb pull << parameters.pull_data_path >> << parameters.pull_data_target >> save_build_cache: description: | Save the Android build-cache. The build cache stores certain outputs that the Android plugin for Gradle generates when building your project (such as unpackaged AARs and pre-dexed remote dependencies). Your clean builds are much faster while using the cache because the build system can simply reuse those cached files during subsequent builds, instead of recreating them. The build cache also works on continuous integration servers and when running multiple build processes on a single local machine. See https://developer.android.com/studio/build/build-cache parameters: cache_prefix: default: v1 description: Used to form part of the cache key type: string steps: - save_cache: key: android-orb-<<parameters.cache_prefix>> name: Save build cache paths: - ~/.android/build-cache - ~/.android/cache save_gradle_cache: description: | Save gradle cache parameters: cache_prefix: default: v1 description: Used to form part of the cache key type: string steps: - save_cache: key: gradle-<< parameters.cache_prefix>>-{{ arch }}-{{ checksum "/tmp/gradle_cache_seed" }} name: Save gradle cache paths: - ~/.gradle/caches - ~/.gradle/wrapper start_emulator: description: | Start an emulator as a background process. The AVD used should already be created. (See "create_avd" command for how one could be created) parameters: additional_args: default: "" description: | Additional args to be passed directly to the emulator command type: string avd_name: description: | The name of the existing AVD to use for the emulator type: string camera_back: default: "" description: | The value to use for the "-camera-back" flag. If set to "", the emulator will be run without the -camera-back flag. type: string camera_front: default: "" description: | The value to use for the "-camera-front" flag. If set to "", the emulator will be run without the -camera-front flag. type: string delay_adb: default: false description: | Whether to run the emulator with the -delay-adb flag type: boolean disable_animations: default: true description: | Whether to disable animations that may interfere with tests, after the emulator starts up type: boolean gpu: default: swiftshader_indirect description: | The value to use for the "-gpu" flag. If set to "", the emulator will be run without the -gpu flag. type: string memory: default: -1 description: | The value to use for the "-memory" flag. If set to -1, the emulator will be run without the -memory flag. type: integer no_audio: default: true description: | Whether to run the emulator with the -noaudio flag type: boolean no_boot_anim: default: true description: | Whether to run the emulator with the -no-boot-anim flag type: boolean no_snapshot: default: true description: | Whether to run the emulator with the -no-snapshot flag type: boolean no_window: default: true description: | Whether to run the emulator with the -no-window flag type: boolean override_args: default: "" description: | If this is set to a non-blank value, the emulator command will be run with the -avd flag and the value of "override_args" (i.e. none of the defaults provided by the orb command will be used) type: string post_emulator_launch_assemble_command: default: ./gradlew assembleDebugAndroidTest description: | If this is set to a non-blank value, the configured command will be run after the emulator has been launched, and before commencing the wait for the emulator to finish starting up. type: string post_emulator_wait_steps: default: [] description: | Steps to execute after waiting for the emulator to start up type: steps pre_emulator_wait_steps: default: [] description: | Steps to execute while before beginning to wait for the emulator to start up type: steps restore_gradle_cache_find_args: default: . -name "build.gradle*" -o -name "settings.gradle*" description: | Use this to customize how the find command is used to look for relevant file changes. type: string restore_gradle_cache_post_emulator_launch: default: true description: | Whether to restore the gradle cache after the emulator has been launched, and before commencing the wait for the emulator to finish starting up. type: boolean restore_gradle_cache_prefix: default: v1 description: | Cache prefix used if the "restore_gradle_cache_post_emulator_launch" parameter is set to true. type: string run_logcat: default: false description: | Whether to run with logcat in the background, after the emulator starts up type: boolean verbose: default: true description: | Whether to run the emulator with the -verbose flag type: boolean wait_for_emulator: default: true description: | Whether to wait for the emulator to start up type: boolean steps: - run: background: true command: | #!/bin/bash if [ -n "${PARAM_OVERRIDE_ARGS}" ]; then echo "override-args parameter was supplied; orb defaults will be overridden" emulator -avd ${PARAM_AVD_NAME} ${PARAM_OVERRIDE_ARGS} else if [ "${PARAM_NO_WINDOW}" -eq 1 ]; then set -- "$@" -no-window fi if [ "${PARAM_NO_AUDIO}" -eq 1 ]; then set -- "$@" -no-audio fi if [ "${PARAM_NO_BOOT_ANIM}" -eq 1 ]; then set -- "$@" -no-boot-anim fi if [ "${PARAM_VERBOSE}" -eq 1 ]; then set -- "$@" -verbose fi if [ "${PARAM_NO_SNAPSHOT}" -eq 1 ]; then set -- "$@" -no-snapshot fi if [ "${PARAM_DELAY_ABD}" -eq 1 ]; then set -- "$@" -delay-adb fi if [ "${PARAM_MEMORY}" != "-1" ]; then set -- "$@" -memory ${PARAM_MEMORY} fi if [ -n "${PARAM_GPU}" ]; then set -- "$@" -gpu "${PARAM_GPU}" fi if [ -n "${PARAM_CAMERA_FRONT}" ]; then set -- "$@" -camera-front "${PARAM_CAMERA_FRONT}" fi if [ -n "${PARAM_CAMERA_BACK}" ]; then set -- "$@" -camera-back "${PARAM_CAMERA_BACK}" fi echo "Starting emulator with arguments $* ${PARAM_ADDITIONAL_ARGS}" emulator -avd ${PARAM_AVD_NAME} "$@" ${PARAM_ADDITIONAL_ARGS} fi environment: PARAM_ADDITIONAL_ARGS: << parameters.additional_args >> PARAM_AVD_NAME: << parameters.avd_name >> PARAM_CAMERA_BACK: << parameters.camera_back >> PARAM_CAMERA_FRONT: << parameters.camera_front >> PARAM_DELAY_ABD: << parameters.delay_adb >> PARAM_GPU: << parameters.gpu >> PARAM_MEMORY: << parameters.memory >> PARAM_NO_AUDIO: << parameters.no_audio >> PARAM_NO_BOOT_ANIM: << parameters.no_boot_anim >> PARAM_NO_SNAPSHOT: << parameters.no_snapshot >> PARAM_NO_WINDOW: << parameters.no_window >> PARAM_OVERRIDE_ARGS: << parameters.override_args >> PARAM_VERBOSE: << parameters.verbose >> name: Start emulator - when: condition: and: - << parameters.restore_gradle_cache_post_emulator_launch >> - equal: - true - << parameters.wait_for_emulator >> steps: - restore_gradle_cache: cache_prefix: << parameters.restore_gradle_cache_prefix >> find_args: << parameters.restore_gradle_cache_find_args >> - when: condition: and: - << parameters.post_emulator_launch_assemble_command >> - equal: - true - << parameters.wait_for_emulator >> steps: - run: command: | # This is meant to do something useful in parallel with the emulator # starting up, like assembling the app, which is required for UI tests << parameters.post_emulator_launch_assemble_command >> name: 'Run: << parameters.post_emulator_launch_assemble_command >>' - when: condition: << parameters.wait_for_emulator >> steps: - << parameters.pre_emulator_wait_steps >> - when: condition: << parameters.wait_for_emulator >> steps: - wait_for_emulator - when: condition: << parameters.run_logcat >> steps: - run: background: true command: | adb logcat name: Logcat - when: condition: << parameters.disable_animations >> steps: - disable_animations - << parameters.post_emulator_wait_steps >> start_emulator_and_run_tests: description: | Creates an AVD, starts an emulator and runs tests. This is a wrapper command that wraps the create_avd, start_emulator and run_tests commands. parameters: additional_avd_args: default: "" description: | Additional args to be passed directly to the avd creation command. You can pass environment variables, using the $ syntax e.g. "$ADDITIONAL_ARGS" type: string additional_emulator_args: default: "" description: | Additional args to be passed directly to the emulator command type: string avd_name: default: test description: | The name of the AVD to create. You can pass environment variables, using the $ syntax e.g. "$AVD_NAME" type: string camera_back: default: "" description: | The value to use for the "-camera-back" flag. If set to "", the emulator will be run without the -camera-back flag. type: string camera_front: default: "" description: | The value to use for the "-camera-front" flag. If set to "", the emulator will be run without the -camera-front flag. type: string delay_adb: default: false description: | Whether to run the emulator with the -delay-adb flag type: boolean disable_animations: default: true description: | Whether to disable animations that may interfere with tests, after the emulator starts up type: boolean gpu: default: swiftshader_indirect description: | The value to use for the "-gpu" flag. If set to "", the emulator will be run without the -gpu flag. type: string install_system_image: default: true description: | Whether to first install the system image via sdkmanager type: boolean kill_emulators: default: true description: | Whether to kill the emulators after the tests complete type: boolean max_tries: default: 2 description: Max number of tries. To disable retries, set this to 1. type: integer memory: default: -1 description: | The value to use for the "-memory" flag. If set to -1, the emulator will be run without the -memory flag. type: integer no_audio: default: true description: | Whether to run the emulator with the -noaudio flag type: boolean no_boot_anim: default: true description: | Whether to run the emulator with the -no-boot-anim flag type: boolean no_output_timeout: default: 10m description: | Use this to configure the no_output_timeout value of the test run type: string no_snapshot: default: true description: | Whether to run the emulator with the -no-snapshot flag type: boolean no_window: default: true description: | Whether to run the emulator with the -no-window flag type: boolean override_emulator_args: default: "" description: | If this is set to a non-blank value, the emulator command will be run with the -avd flag and the value of "override_args" (i.e. none of the defaults provided by the orb command will be used) type: string post_emulator_launch_assemble_command: default: ./gradlew assembleDebugAndroidTest description: | If this is set to a non-blank value, the configured command will be run after the emulator has been launched, and before commencing the wait for the emulator to finish starting up. type: string post_emulator_wait_steps: default: [] description: | Steps to execute after waiting for the emulator to start up type: steps post_run_tests_steps: default: [] description: | Steps to run after the tests type: steps pre_emulator_wait_steps: default: [] description: | Steps to execute while before beginning to wait for the emulator to start up type: steps pre_run_tests_steps: default: [] description: | Steps to run before the tests type: steps pre_test_command: default: ' ' description: | Command to run prior to runnning the test command You can pass environment variables, using the $ syntax e.g. "$PRE_TEST_COMMAND" type: string pull_data: default: false description: | Whether to pull data after running tests type: boolean pull_data_path: default: data description: | Emulator directory to pull data from type: string pull_data_target: default: . description: | Location to save pulled data type: string restore_gradle_cache_find_args: default: . -name "build.gradle*" -o -name "settings.gradle*" description: | Use this to customize how the find command is used to look for relevant file changes. type: string restore_gradle_cache_post_emulator_launch: default: true description: | Whether to restore the gradle cache after the emulator has been launched, and before commencing the wait for the emulator to finish starting up. type: boolean restore_gradle_cache_prefix: default: v1 description: | Cache prefix used if the "restore_gradle_cache_post_emulator_launch" parameter is set to true. type: string retry_interval: default: 5 description: Duration in seconds to wait before the next try type: integer run_logcat: default: false description: | Whether to run with logcat in the background, after the emulator starts up type: boolean run_tests_working_directory: default: . description: Working directory to run the tests in type: string save_gradle_cache: default: true description: | Whether to write to the gradle cache after the tests have run type: boolean system_image: default: system-images;android-29;default;x86 description: | Name of system image e.g. "system-images;android-29;default;x86". It should match the name seen in the "sdkmanager --list" output. You can pass environment variables, using the $ syntax e.g. "$SYSTEM_IMAGE" type: string test_command: default: ./gradlew connectedDebugAndroidTest description: | Command to run in order to run the tests You can pass environment variables, using the $ syntax e.g. "$TEST_COMMAND" type: string verbose: default: true description: | Whether to run the emulator with the -verbose flag type: boolean wait_for_emulator: default: true description: | Whether to wait for the emulator to start up type: boolean steps: - create_avd: additional_args: << parameters.additional_avd_args >> avd_name: << parameters.avd_name >> install: << parameters.install_system_image >> system_image: <<parameters.system_image>> - start_emulator: additional_args: << parameters.additional_emulator_args >> avd_name: << parameters.avd_name >> camera_back: << parameters.camera_back >> camera_front: << parameters.camera_front >> delay_adb: << parameters.delay_adb >> disable_animations: << parameters.disable_animations >> gpu: << parameters.gpu >> memory: << parameters.memory >> no_audio: << parameters.no_audio >> no_boot_anim: << parameters.no_boot_anim >> no_snapshot: << parameters.no_snapshot >> no_window: << parameters.no_window >> override_args: << parameters.override_emulator_args >> post_emulator_launch_assemble_command: << parameters.post_emulator_launch_assemble_command >> post_emulator_wait_steps: << parameters.post_emulator_wait_steps >> pre_emulator_wait_steps: << parameters.pre_emulator_wait_steps >> restore_gradle_cache_find_args: << parameters.restore_gradle_cache_find_args >> restore_gradle_cache_post_emulator_launch: << parameters.restore_gradle_cache_post_emulator_launch >> restore_gradle_cache_prefix: << parameters.restore_gradle_cache_prefix >> run_logcat: << parameters.run_logcat >> verbose: << parameters.verbose >> wait_for_emulator: << parameters.wait_for_emulator >> - << parameters.pre_run_tests_steps >> - run_tests: max_tries: << parameters.max_tries >> no_output_timeout: << parameters.no_output_timeout >> pre_test_command: << parameters.pre_test_command >> pull_data: << parameters.pull_data >> pull_data_path: << parameters.pull_data_path >> pull_data_target: << parameters.pull_data_target >> retry_interval: << parameters.retry_interval >> test_command: << parameters.test_command >> working_directory: << parameters.run_tests_working_directory >> - << parameters.post_run_tests_steps >> - when: condition: << parameters.save_gradle_cache >> steps: - save_gradle_cache: cache_prefix: << parameters.restore_gradle_cache_prefix >> - when: condition: << parameters.kill_emulators >> steps: - kill_emulators wait_for_emulator: description: | Wait for the emulator to start. Requires the "circle-android" script to be present in PATH. steps: - run: command: | circle-android wait-for-boot name: Wait for the emulator to start executors: android_docker: description: | Select a CircleCI convenience image to get building on Android. See https://circleci.com/developer/images/image/cimg/android#image-tags for a full list of the available images. docker: - image: cimg/android:<< parameters.tag >> parameters: resource_class: default: medium description: Resource class used for the executor. enum: - small - medium - medium+ - large - xlarge - 2xlarge - 2xlarge+ type: enum tag: description: | The Android image tag to use. Choose a tag from https://circleci.com/developer/images/image/cimg/android#image-tags. type: string resource_class: << parameters.resource_class >> android_machine: description: | This selects an Android machine image. CircleCI's Android machine images are recommended for Android emulator tests. machine: image: android:<< parameters.tag >> resource_class: << parameters.resource_class >> parameters: resource_class: default: large description: | Resource class used for the executor. It is recommended to use large and above to avoid memory issues such as process crashes when running emulator tests. enum: - medium - large - xlarge - 2xlarge type: enum tag: description: | Name of CircleCI Android machine image to use. Android machine tags can be found at https://circleci.com/developer/machine/image/android#image-tags type: string jobs: build: description: | Start building an Android project on CircleCI executor: << parameters.executor >> parameters: executor: description: Executor for the job type: executor steps: - checkout - accept_licenses deploy_to_play_store: description: | Deploy an android app on CircleCI to the Google Play Store using Fastlane. For use with CirceCI Environment Variables. executor: << parameters.executor >> parameters: base64_keystore: default: BASE64_KEYSTORE description: Your base64 keystore type: env_var_name checkout: default: true description: Whether to run the checkout step type: boolean executor: description: Executor for the job type: executor fastlane_working_directory: default: . description: Working directory to run fastlane commands in type: string google_play_key: default: GOOGLE_PLAY_KEY description: Your google play key type: env_var_name keystore_location: default: . description: The location of your decrypted keystore type: string keystore_properties_working_directory: default: . description: Working directory to create keystore.properties in type: string lane_name: default: deploy description: The name of the lane fastlane will execute type: string release_key_alias: default: RELEASE_KEY_ALIAS description: Release key alias type: env_var_name release_key_password: default: RELEASE_KEY_PASSWORD description: Password for your release key type: env_var_name release_keystore: default: ./keystore description: Points to the location of your decrypted keystore type: string release_store_password: default: RELEASE_STORE_PASSWORD description: Password for your keystore type: env_var_name steps: - when: condition: << parameters.checkout >> steps: - checkout - decode_keystore: base64_keystore: << parameters.base64_keystore >> keystore_location: << parameters.keystore_location >> - create_keystore_properties: release_key_alias: << parameters.release_key_alias >> release_key_password: << parameters.release_key_password >> release_keystore: << parameters.release_keystore >> release_store_password: << parameters.release_store_password >> working_directory: << parameters.keystore_properties_working_directory >> - create_google_play_key: google_play_key: << parameters.google_play_key >> - fastlane_deploy: lane_name: << parameters.lane_name >> working_directory: << parameters.fastlane_working_directory >> run_ui_tests: description: | Creates an AVD, starts an emulator and runs Android UI tests. This is a job that wraps the "start_emulator_and_run_tests" command. executor: << parameters.executor >> parameters: additional_avd_args: default: "" description: | Additional args to be passed directly to the avd creation command type: string additional_emulator_args: default: "" description: | Additional args to be passed directly to the emulator command type: string avd_name: default: test description: | The name of the AVD to create type: string camera_back: default: "" description: | The value to use for the "-camera-back" flag. If set to "", the emulator will be run without the -camera-back flag. type: string camera_front: default: "" description: | The value to use for the "-camera-front" flag. If set to "", the emulator will be run without the -camera-front flag. type: string checkout: default: true description: Whether to run the checkout step type: boolean delay_adb: default: false description: | Whether to run the emulator with the -delay-adb flag type: boolean disable_animations: default: true description: | Whether to disable animations that may interfere with tests, after the emulator starts up type: boolean executor: description: Executor for the job type: executor gpu: default: swiftshader_indirect description: | The value to use for the "-gpu" flag. If set to "", the emulator will be run without the -gpu flag. type: string install_system_image: default: true description: | Whether to first install the system image via sdkmanager type: boolean kill_emulators: default: true description: | Whether to kill the emulators after the tests complete type: boolean max_tries: default: 2 description: Max number of tries. To disable retries, set this to 1. type: integer memory: default: -1 description: | The value to use for the "-memory" flag. If set to -1, the emulator will be run without the -memory flag. type: integer no_audio: default: true description: | Whether to run the emulator with the -noaudio flag type: boolean no_boot_anim: default: true description: | Whether to run the emulator with the -no-boot-anim flag type: boolean no_output_timeout: default: 10m description: | Use this to configure the no_output_timeout value of the test run type: string no_snapshot: default: true description: | Whether to run the emulator with the -no-snapshot flag type: boolean no_window: default: true description: | Whether to run the emulator with the -no-window flag type: boolean override_emulator_args: default: "" description: | If this is set to a non-blank value, the emulator command will be run with the -avd flag and the value of "override_args" (i.e. none of the defaults provided by the orb command will be used) type: string post_emulator_launch_assemble_command: default: ./gradlew assembleDebugAndroidTest description: | If this is set to a non-blank value, the configured command will be run after the emulator has been launched, and before commencing the wait for the emulator to finish starting up. type: string post_emulator_wait_steps: default: [] description: | Steps to execute after waiting for the emulator to start up type: steps post_run_tests_steps: default: [] description: | Steps to run after the tests type: steps pre_emulator_wait_steps: default: [] description: | Steps to execute while before beginning to wait for the emulator to start up type: steps pre_run_tests_steps: default: [] description: | Steps to run before the tests type: steps pre_test_command: default: ' ' description: Command to run prior to runnning the test command type: string pull_data: default: false description: | Whether to pull data after running tests type: boolean pull_data_path: default: data description: | Emulator directory to pull data from type: string pull_data_target: default: . description: | Location to save pulled data type: string restore_gradle_cache_find_args: default: . -name "build.gradle*" -o -name "settings.gradle*" description: | Use this to customize how the find command is used to look for relevant file changes. type: string restore_gradle_cache_post_emulator_launch: default: true description: | Whether to restore the gradle cache after the emulator has been launched, and before commencing the wait for the emulator to finish starting up. type: boolean restore_gradle_cache_prefix: default: v1 description: | Cache prefix used if the "restore_gradle_cache_post_emulator_launch" parameter is set to true. type: string retry_interval: default: 5 description: Duration in seconds to wait before the next try type: integer run_logcat: default: false description: | Whether to run with logcat in the background, after the emulator starts up type: boolean run_tests_working_directory: default: . description: Working directory to run the tests in type: string save_gradle_cache: default: true description: | Whether to write to the gradle cache after the tests have run type: boolean system_image: default: system-images;android-29;default;x86 description: | Name of system image e.g. "system-images;android-29;default;x86". It should match the name seen in the "sdkmanager --list" output. type: string test_command: default: ./gradlew connectedDebugAndroidTest description: Command to run in order to run the tests type: string verbose: default: true description: | Whether to run the emulator with the -verbose flag type: boolean wait_for_emulator: default: true description: | Whether to wait for the emulator to start up type: boolean steps: - when: condition: << parameters.checkout >> steps: - checkout - start_emulator_and_run_tests: additional_avd_args: << parameters.additional_avd_args >> additional_emulator_args: << parameters.additional_emulator_args >> avd_name: << parameters.avd_name >> camera_back: << parameters.camera_back >> camera_front: << parameters.camera_front >> delay_adb: << parameters.delay_adb >> disable_animations: << parameters.disable_animations >> gpu: << parameters.gpu >> install_system_image: << parameters.install_system_image >> kill_emulators: << parameters.kill_emulators >> max_tries: << parameters.max_tries >> memory: << parameters.memory >> no_audio: << parameters.no_audio >> no_boot_anim: << parameters.no_boot_anim >> no_output_timeout: << parameters.no_output_timeout >> no_snapshot: << parameters.no_snapshot >> no_window: << parameters.no_window >> override_emulator_args: << parameters.override_emulator_args >> post_emulator_launch_assemble_command: << parameters.post_emulator_launch_assemble_command >> post_emulator_wait_steps: << parameters.post_emulator_wait_steps >> post_run_tests_steps: << parameters.post_run_tests_steps >> pre_emulator_wait_steps: << parameters.pre_emulator_wait_steps >> pre_run_tests_steps: << parameters.pre_run_tests_steps >> pre_test_command: << parameters.pre_test_command >> pull_data: << parameters.pull_data >> pull_data_path: << parameters.pull_data_path >> pull_data_target: << parameters.pull_data_target >> restore_gradle_cache_find_args: << parameters.restore_gradle_cache_find_args >> restore_gradle_cache_post_emulator_launch: << parameters.restore_gradle_cache_post_emulator_launch >> restore_gradle_cache_prefix: << parameters.restore_gradle_cache_prefix >> retry_interval: << parameters.retry_interval >> run_logcat: << parameters.run_logcat >> run_tests_working_directory: << parameters.run_tests_working_directory >> save_gradle_cache: << parameters.save_gradle_cache >> system_image: <<parameters.system_image>> test_command: << parameters.test_command >> verbose: << parameters.verbose >> wait_for_emulator: << parameters.wait_for_emulator >> examples: granular_commands: description: | An example of using the more granular commands of the orb together, to achieve something similar to using the "start_emulator_and_run_tests" command or the "run_ui_tests" job. usage: version: "2.1" orbs: android: circleci/android@3.0.0 jobs: test: executor: name: android/android_machine resource_class: large tag: default steps: - checkout - android/create_avd: avd_name: myavd install: true system_image: system-images;android-31;default;x86_64 - android/start_emulator: avd_name: myavd no_window: true restore_gradle_cache_prefix: v1a - android/run_tests - android/save_gradle_cache: cache_prefix: v1a workflows: test: jobs: - test override_machine_resource_class: description: | An example of overriding the android_machine executor's default resource class usage: version: "2.1" orbs: android: circleci/android@3.0.0 workflows: test: jobs: - android/run_ui_tests: executor: name: android/android_machine resource_class: xlarge tag: default run_ui_tests_job: description: | A simple example of using the run_ui_tests job, using most of the default parameters. Parameters like the system_image and emulator options (e.g. "no_window") may need to be adjusted from the defaults, according to your project. usage: version: "2.1" orbs: android: circleci/android@3.0.0 workflows: test: jobs: - android/run_ui_tests: executor: name: android/android_machine resource-class: large tag: 2024.01.1 system_image: system-images;android-31;default;x86_64 start_emulator_and_run_tests: description: | A simple example of using the start_emulator_and_run_tests command in a job, using most of the default parameters. Parameters like the system_image and emulator options (e.g. "no_window") may need to be adjusted from the defaults, according to your project. usage: version: "2.1" orbs: android: circleci/android@3.0.0 jobs: test: executor: name: android/android_machine resource_class: large tag: default steps: - checkout - android/start_emulator_and_run_tests: system_image: system-images;android-31;default;x86_64 workflows: test: jobs: - test test_matrix: description: | A simple example of using a test matrix to test on different emulators. usage: version: "2.1" orbs: android: circleci/android@3.0.0 workflows: test: jobs: - android/run_ui_tests: matrix: parameters: system_image: - system-images;android-31;default;x86_64 - system-images;android-31;default;x86_64 name: ui-tests-<<matrix.system_image>>
Developer Updates
Get tips to optimize your builds
Or join our research panel and give feedback
By submitting this form, you are agreeing to ourTerms of UseandPrivacy Policy.