- Home
- Workflows and Pipelines
- Workflows
- Workflow recipes for Android apps
Workflow recipes for Android apps
Workflow recipes specifically for iOS apps. Some of these can be used for the iOS versions of cross-platform apps, while others are specifically meant for native iOS apps.
Workflow Recipes provide ready-made solutions for common Workflow tasks.
Here you can find Workflow recipes specifically for iOS apps. Some of these can be used for the iOS versions of cross-platform apps, too while some are specifically meant for native iOS apps.
(Android) Deploy to Visual Studio App Center
Description
Build and distribute your app to testers via Visual Studio App Center.
Prerequisites
-
An existing Visual Studio App Center project where your app is registered.
-
Adding the API token as a Secret to your Bitrise app with the name
APPCENTER_API_TOKEN
. -
If you want to deploy a release build, don't forget to set up code signing on Bitrise to build and sign the APK with your release key.
Instructions
-
Add the Android Build Step and set the following inputs:
-
Build type: set this to apk.
-
Variant: use release, debug, or one of your custom variants if you have any.
-
-
If you build a release variant, add the Android Sign Step.
You can skip this if you plan to deploy an unsigned debug variant.
-
Add the AppCenter iOS Deploy Step and set the following inputs:
-
API Token:
$APPCENTER_API_TOKEN
-
Owner name: for example,
my-company
. -
App name: For example,
my-app
. Use the App Center CLI to get the app name since it might not be the same as the one you can see on the Visual Studio App Center website.
-
Check out other options in the Step documentation or in the Workflow Editor.
bitrise.yml
- android-build@1: inputs: - variant: release - build_type: apk - sign-apk@1: {} - appcenter-deploy-android@2: inputs: - owner_name: my-company - app_name: my-app - app_path: "$BITRISE_APK_PATH" - api_token: "$APPCENTER_API_TOKEN"
(Android) Deploy to Firebase App Distribution
Description
Build and distribute your app to testers via Firebase App Distribution. This example builds and deploys an APK, but the Workflow can be tweaked to distribute AAB instead.
Prerequisites
-
An existing Firebase project where your exact package name is registered. See the Firebase documentation for details.
-
Obtain a token from Firebase by running
firebase login:ci
locally. See the Firebase CLI docs for details. -
Add this token as a Secret to your Bitrise app with the name
FIREBASE_TOKEN
. -
Get your Firebase App ID from your project's General Settings page and pass this value as an input to the Firebase App Distribution Step.
-
If you want to deploy a release build, don't forget to set up code signing on Bitrise to build and sign the APK with your release key.
Instructions
-
Add the Android Build Step and set the following inputs:
-
Build type: Set this to apk.
-
Variant: Use
release
,debug
, or one of your custom variants if you have any.
-
-
If you build a release variant, add the Android Sign Step.
You can skip this if you plan to deploy an unsigned debug variant.
-
Add the Firebase App Distribution Step and set the following inputs:
-
Firebase token: use the secret Env var previously defined:
$FIREBASE_TOKEN
. -
App path: this should point to the APK that the previous steps have built and signed. By default, it's located at
$BITRISE_DEPLOY_DIR/app-release-bitrise-signed.apk
, but the exact file name might be different based on your project config. -
Firebase App ID: get your Firebase App ID from your project's General Settings page and pass this value as an input to the Firebase App Distribution Step.
-
Optional: you can define test groups or individual testers in the Step inputs
-
bitrise.yml
- android-build@1: inputs: - variant: release - build_type: apk - sign-apk@1: {} - firebase-app-distribution@0: inputs: - firebase_token: $FIREBASE_TOKEN - app_path: $BITRISE_DEPLOY_DIR/app-release-bitrise-signed.apk - app: your_app_id_from_firebase - testers: [email protected] # optional - groups: qa-team #optional
(Android) Deploy to Google Play (Internal, Alpha, Beta, Production)
Description
Build an Android app and upload to Google Play to internal, alpha, beta or production track.
Prerequisites
-
An Android keystore file is uploaded to Bitrise.
-
Google Play API Access is set up.
Instructions
-
(Optional) Add the Change Android versionCode and versionName Step. Set the input variables:
-
Path to the build.gradle file: The default value is
$PROJECT_LOCATION/$MODULE/build.gradle
and in most cases you don't have to change it. -
New versionName: for example,
1.0.1
-
New versionCode: for example,
42
.
-
-
Add the Android Build Step and set the following inputs:
-
Build type: Set this to aab.
-
Variant: Use
release
,debug
, or one of your custom variants if you have any. -
Module: for example
$MODULE
.
-
-
Add the Android Sign Step.
-
Add the Google Play Deploy Step and set the following inputs:
-
Service Account JSON key file path:
$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL
. -
Package name: for example,
com.your.package.name
. -
Track: Choose one of internal, alpha, beta, or production.
-
Status: The status of a release. For more information, see the Google API reference. Recommended
draft
for production andcompleted
for internal test builds. -
Check the other options in the Workflow Editor or in the Step documentation.
Deploy to Google Play fails with Error 403
You might experience that Deploy to Google Play Step fails with error:
"error: Failed to perform edit insert call, error: googleapi: Error 403: The caller does not have permission, forbidden"
For possible solutions, check out our Knowledge Base article.
-
bitrise.yml
- change-android-versioncode-and-versionname@1: inputs: - new_version_name: 1.0.1 - new_version_code: '42' - build_gradle_path: "$PROJECT_LOCATION/$MODULE/build.gradle" - android-build@1: inputs: - project_location: "$PROJECT_LOCATION" - module: "$MODULE" - build_type: aab - variant: release - sign-apk@1: {} - google-play-deploy@3: inputs: - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL" - package_name: io.bitrise.sample.android - status: completed - track: internal
(Android) Deploy to Bitrise.io
Description
Build and distribute your app to testers via the Bitrise.io Ship add-on.Deploying with Ship
Instructions
Deploying a release build
If you want to deploy a release build, don't forget to set up code signing on Bitrise to build and sign the APK with your release key.
-
Add the Android Build Step and set the following inputs:
-
Build type: Set this to apk.
-
Variant: Use
release
,debug
, or one of your custom variants if you have any.
-
-
If you build a release variant, add the Android Sign Step.
You can skip this if you plan to deploy an unsigned debug variant.
-
Add a Deploy to Bitrise.io - Apps, Logs, Artifacts Step.
bitrise.yml
- android-build@1: inputs: - variant: release - build_type: apk - sign-apk@1: {} - deploy-to-bitrise-io@2: {}
(Android) Example CI Workflow
Description
Example Workflow for commits on the main branch of an Android app. The Workflow contains:
-
Filling the cache for upcoming pull request builds.
bitrise.yml
--- format_version: '11' default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git project_type: android workflows: ci: steps: - activate-ssh-key@4: run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}' - git-clone@6: {} - cache-pull@2: {} - android-unit-test@1: inputs: - project_location: $PROJECT_LOCATION - variant: $VARIANT - android-build-for-ui-testing@0: inputs: - variant: $VARIANT - module: $MODULE - virtual-device-testing-for-android@1: inputs: - test_type: instrumentation - android-lint@0: inputs: - variant: "$VARIANT" - android-build@1: inputs: - project_location: "$PROJECT_LOCATION" - module: "$MODULE" - variant: "$VARIANT" - deploy-to-bitrise-io@2: {} - slack@3: inputs: - channel: "#build-notifications" - webhook_url: "$SLACK_WEBHOOK" - cache-push@2: {} app: envs: - opts: is_expand: false PROJECT_LOCATION: "." - opts: is_expand: false MODULE: app - VARIANT: debug opts: is_expand: false trigger_map: - push_branch: main workflow: ci
(Android) Example nightly Workflow
Description
Example Workflow for nightly builds of an Android app. The Workflow contains:
-
Setting the version code and version name.
By default the app will get the build number (
$BITRISE_BUILD_NUMBER
) as the version code. -
Building a release Android App Bundle and uploading to Google Play internal testing.
bitrise.yml
--- format_version: '11' default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git project_type: android workflows: nightly: steps: - activate-ssh-key@4: run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}' - git-clone@6: {} - cache-pull@2: {} - change-android-versioncode-and-versionname@1: inputs: - new_version_name: 1.0.0 - build_gradle_path: "$PROJECT_LOCATION/$MODULE/build.gradle" - android-build@1: inputs: - project_location: "$PROJECT_LOCATION" - module: "$MODULE" - build_type: aab - variant: release - sign-apk@1: {} - google-play-deploy@3: inputs: - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL" - package_name: io.bitrise.sample.android - status: completed - track: internal - android-build@1: inputs: - project_location: "$PROJECT_LOCATION" - module: "$MODULE" - variant: "$VARIANT" - deploy-to-bitrise-io@2: {} - create-install-page-qr-code@1: {} - slack@3: inputs: - channel: "#build-notifications" - thumb_url: "$BITRISE_PUBLIC_INSTALL_PAGE_QR_CODE_IMAGE_URL" - webhook_url: "$SLACK_WEBHOOK" - cache-push@2: {} app: envs: - opts: is_expand: false PROJECT_LOCATION: "." - opts: is_expand: false MODULE: app - VARIANT: debug opts: is_expand: false
(Android) Example pull request Workflow
Description
Example Workflow for Android pull request validation. The Workflow contains:
-
Triggering the Workflow for pull requests.
bitrise.yml
--- format_version: '11' default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git project_type: android workflows: pull-request: steps: - activate-ssh-key@4: run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}' - git-clone@6: {} - cache-pull@2: {} - android-unit-test@1: inputs: - project_location: $PROJECT_LOCATION - variant: $VARIANT - android-build-for-ui-testing@0: inputs: - variant: $VARIANT - module: $MODULE - virtual-device-testing-for-android@1: inputs: - test_type: instrumentation - android-lint@0: inputs: - variant: "$VARIANT" - android-build@1: inputs: - project_location: "$PROJECT_LOCATION" - module: "$MODULE" - variant: "$VARIANT" - deploy-to-bitrise-io@2: {} - create-install-page-qr-code@1: {} - comment-on-github-pull-request@0: inputs: - body: |- ![QR code]($BITRISE_PUBLIC_INSTALL_PAGE_QR_CODE_IMAGE_URL) $BITRISE_PUBLIC_INSTALL_PAGE_URL - personal_access_token: "$GITHUB_ACCESS_TOKEN" - cache-push@2: {} app: envs: - opts: is_expand: false PROJECT_LOCATION: "." - opts: is_expand: false MODULE: app - VARIANT: debug opts: is_expand: false trigger_map: - pull_request_source_branch: "*" workflow: pull-request
(Android) Run instrumentation tests on virtual devices
Description
Run instrumentation (for example, Espresso) or robo/gameloop tests on virtual devices. Our device testing solution is based on Firebase Test Lab. You can find the resulting logs, videos and screenshots on Bitrise.
Instructions
-
Add an Android Build for UI Testing Step. Set the input variables:
-
Project Location: Use the default
$BITRISE_SOURCE_DIR
or$PROJECT_LOCATION
. You can set a specific path but the automatically exposed Environment Variables are usually the best option. -
Variant: Use the
$VARIANT
Enviromment Variable, or specify a variant manually. -
Module: Specify one or leave it blank to run tests in all of the modules.
-
-
Add a Virtual Device Testing for Android Step. Set the input variables:
-
Test type: instrumentation (or robo or gameloop)
-
(Optional) Test devices (default: NexusLowRes,24,en,portrait).
-
-
Add a Deploy to Bitrise.io Step that makes the test results available in the Test Reports add-on.
Potential issues with running instrumentation tests on virtual devices
You might encounter some unexpected issues while running instrumentation tests on virtual devices. You can find some examples and possible solutions in our Knowledge Base:
bitrise.yml
- android-build-for-ui-testing@0: inputs: - variant: $VARIANT - module: $MODULE - virtual-device-testing-for-android@1: inputs: - test_type: instrumentation - deploy-to-bitrise-io@2: {}
(Android) Example release Workflow
Description
Example Workflow for uploading a release draft of an app to Google Play. The Workflow contains:
-
Setting the version name based on Env Vars passed to the build (
$VERSION_NAME
). -
Creating a release Android App Bundle and uploading it to Google Play.
bitrise.yml
--- format_version: '11' default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git project_type: android workflows: release: steps: - activate-ssh-key@4: run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}' - git-clone@6: {} - change-android-versioncode-and-versionname@1: inputs: - new_version_name: "$VERSION_NAME" - new_version_code: "$BITRISE_BUILD_NUMBER" - build_gradle_path: "$PROJECT_LOCATION/$MODULE/build.gradle" - android-build@1: inputs: - project_location: "$PROJECT_LOCATION" - module: "$MODULE" - build_type: aab - variant: release - sign-apk@1: {} - google-play-deploy@3: inputs: - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL" - package_name: io.bitrise.sample.android - status: draft - track: production app: envs: - opts: is_expand: false PROJECT_LOCATION: "." - opts: is_expand: false MODULE: app - VARIANT: debug opts: is_expand: false
(Android) Run Lint
Description
Runs Lint on your Android project.
Instructions
-
Add the Android Lint Step. Set the input variables:
-
Project Location: Use the default
$BITRISE_SOURCE_DIR
or$PROJECT_LOCATION
.You can set a specific path but the automatically exposed Environment Variables are usually the best option.
-
Variant: Use the
$VARIANT
Enviromment Variable, or specify a variant manually. -
Module: Specify one or leave it blank to run lint in all of the modules.
-
-
Add a Deploy to Bitrise.io Step. This Step uploads the lint report as a build artifact.
bitrise.yml
- android-lint@0: inputs: - variant: $VARIANT - deploy-to-bitrise-io@2: {}
Turn on Gradle build profiling
Description
Generate and store a performance report of every Gradle build to spot build speed issues or compare different builds.
Instructions
No matter what Android or Gradle Step you use in your Bitrise Workflow, there is an option to define additional command line arguments for Gradle. Add --profile
to the relevant input variable to generate a performance report of the Gradle tasks. In the example
below, we are adding the argument to the Android Unit Test Step.
-
Add the Android Unit Test Step to your Workflow and set the necessary input variables:
-
Project location:
$PROJECT_LOCATION
. -
Module:
$MODULE
. -
Variant:
$VARIANT
. -
Arguments:
--profile2
.
-
-
Add a Script Step to the end of the Workflow to compress the report files and copy the ZIP file to the deploy directory:
#!/usr/bin/env bash # fail if any commands fails set -e # debug log set -x zip -r $BITRISE_DEPLOY_DIR/gradle-profile.zip $PROJECT_LOCATION/build/reports/profile
Gradle creates the HTML report in
build/reports/profile/
, so we need to take all files in that folder (HTML, CSS and JS files), compress them, and move the ZIP archive to$BITRISE_DEPLOY_DIR
. Files in this folder can be accessed on the build page’s Artifacts tab. -
Trigger a manual build of your app.
-
Download and unarchive the
gradle-profile.zip
file, then open the HTML report in your browser. -
Go to the Artifacts tab and check the various aspects of the build in the report:
-
The Summary tab shows time spent on things other than task execution.
-
The Task execution tab lists all tasks sorted by execution time.
-
Cached tasks are marked as UP-TO-DATE. This helps to fine-tune the Bitrise Cache Steps by comparing the reports of multiple builds.Caching
For Gradle optimization ideas, check out this article by Google.
If you only want to display task execution times only in the build log, you can use the build-time-tracker plugin.
-
bitrise.yml
- android-unit-test@1: inputs: - project_location: $PROJECT_LOCATION - module: $MODULE - arguments: "--profile" - variant: $VARIANT - script@1: title: Collect Gradle profile report inputs: - content: |- #!/usr/bin/env bash # fail if any commands fails set -e # debug log set -x zip -r $BITRISE_DEPLOY_DIR/gradle-profile.zip $PROJECT_LOCATION/build/reports/profile - deploy-to-bitrise-io@1: {}
(Android) Run unit tests
Description
Run unit tests (for example, testDebugUnitTest
) for an Android app.
Instructions
-
Add an Android Unit Test Step.
Set the input variables:
-
Project Location: Use the default
$BITRISE_SOURCE_DIR
or$PROJECT_LOCATION
. You can set a specific path but the automatically exposed Environment Variables are usually the best option. -
Variant: Use the
$VARIANT
Enviromment Variable, or specify a variant manually. -
Module: Specify one or leave it blank to run tests in all of the modules.
-
-
Add a Deploy to Bitrise.io Step that makes the test results available in the Test Reports add-on.
bitrise.yml
- android-unit-test@1: inputs: - project_location: $PROJECT_LOCATION - variant: $VARIANT - deploy-to-bitrise-io@2: {}
(Android) Run tests using the emulator
Description
Run any kind of tests (unit, instrumentation) on a local emulator instance.
Instructions
-
Add an AVD Manager Step. To customize the emulator, see the Step configuration.
Using the AVD Manager Step
The AVD Manager starts in the background, which can take several minutes. Because of that, we recommend adding the AVD Manager Step at the beginning of your Workflow (before Activate SSH key (RSA private key) Step and the Git Clone Step) to speed up your builds.
-
Add a Android Build for UI Testing Step, and configure the required inputs.
-
Add a Wait for Android emulator Step.
-
Add an Android Instrumented Test Step, and configure the required inputs.
-
Add an Export test results to Test Reports add-on Step with the following inputs:
-
The name of the test:
Emulator tests
. -
Test result base path:
$BITRISE_SOURCE_DIR/app/build/outputs/androidTest-results
.You might want to adjust the path based on the module name(s) in your project.
-
Test result search pattern:
*.xml
.
-
-
Add a Deploy to Bitrise.io Step that makes the test results available in the Test Reports add-on.
bitrise.yml
- avd-manager@1: {} - android-build-for-ui-testing@0: inputs: - module: "$ANDROID_TESTING_MODULE" - variant: "$ANDROID_V_DEBUG" - wait-for-android-emulator@1: - android-instrumented-test@0: {} - custom-test-results-export@0: inputs: - search_pattern: "*.xml" - base_path: $BITRISE_SOURCE_DIR/app/build/outputs/androidTest-results - test_name: Emulator tests - deploy-to-bitrise-io@2: