Android
Use a CI pipeline to build and test an Android application.
You can build and test Android applications using a Linux or Mac platform on Harness Cloud, a self-managed Kubernetes cluster, or a local runner build infrastructure.
This guide assumes you've created a Harness CI pipeline.
Specify architecture
You can build and test Android apps on a Linux or Mac platform on Harness Cloud build infrastructure.
stages:
- stage:
name: Build
identifier: Build
type: CI
spec:
cloneCodebase: true
platform:
os: Linux
arch: Amd64
runtime:
type: Cloud
spec: {}To use M1 machines with Harness Cloud, use the Arm64 architecture.
stages:
- stage:
name: build
identifier: build
type: CI
spec:
cloneCodebase: true
platform:
os: MacOS ## selects macOS operating system
arch: Arm64 ## selects M1 architecture
runtime:
type: Cloud
spec: {}If you need to use Intel-based architecture, Rosetta is pre-installed on Harness Cloud's M1 machines. If you need to use it, add the prefix arch -x86_64 to commands in your scripts. Keep in mind that running apps through Rosetta can impact performance. Use native Apple Silicon apps whenever possible to ensure optimal performance.
You can build Android apps on a Linux or Mac platform on self-managed build infrastructures, including Kubernetes clusters, VMs, and local runners.
This example sets up a Linux platform on a Kubernetes cluster build infrastructure.
stages:
- stage:
name: build
identifier: build
description: ""
type: CI
spec:
cloneCodebase: true
infrastructure:
type: KubernetesDirect
spec:
connectorRef: YOUR_KUBERNETES_CLUSTER_CONNECTOR_ID
namespace: YOUR_NAMESPACE
automountServiceAccountToken: true
nodeSelector: {}
os: LinuxTo configure a self-managed macOS build infrastructure, go to Set up a macOS VM build infrastructure with Anka Registry or Set up a local runner build infrastructure.
This example uses a VM build infrastructure:
stages:
- stage:
name: build
identifier: build
description: ""
type: CI
spec:
cloneCodebase: true
infrastructure:
type: VM
spec:
type: Pool
spec:
poolName: YOUR_VM_POOL_NAME
os: MacOSIf you need to use Intel-based architecture and Rosetta is not already installed on your build infrastructure machines, you can use a Run step to install this dependency. Keep in mind that running apps through Rosetta can impact performance. Use native Apple Silicon apps whenever possible to ensure optimal performance.
Install dependencies
Many Android packages, such as command-line tools and an emulator, are already installed on Harness Cloud Linux machines. For more information about preinstalled tools and libraries, go to the Harness Cloud image specifications.
Use Run steps to install dependencies in the build environment.
Use Run steps to install dependencies in the build environment.
Cache dependencies
Add caching to your stage.
Use Cache Intelligence by adding caching to your stage.spec:
You can use built-in steps to:
Here's an example of a pipeline with Save Cache to S3 and Restore Cache from S3 steps. It also includes a Run step that creates the .ipa archive with xcodebuild archive and xcodebuild --exportArchive.
Build and run tests
You can use Run or Test steps to run tests in Harness CI.
If you're using Kotlin, you can improve your unit test times with Harness' Test Intelligence feature.
Harness CI also supports test splitting (parallelism) for both Run and Test steps.
If you want to view test results in Harness, make sure your test commands produce reports in JUnit XML format and that your steps include the reports specification.
If you want to view test results in Harness, make sure your test commands produce reports in JUnit XML format and that your steps include the reports specification.
Specify version
Android packages, including Android SDK tools and fastlane, are pre-installed on Harness Cloud machines. For details about all available tools and versions, go to Platforms and image specifications.
If you need to install additional versions, use a Run step. These examples use faberNovel/docker-android and fastlane.
Specify the desired Android Docker image tag in your steps. There is no need for a separate install step when using Docker.
These examples use faberNovel/docker-android and fastlane.
Deploy to the Google Play Store
The following examples use fastlane to deploy an app to the Google Play Store. These are intended as examples only. They do not provide complete firebase configuration or app distribution requirements. To learn more about app distribution, go to the Google documentation on Firebase App Distribution and the fastlane documentation on Deploying to Google Play using fastlane.
Full pipeline examples
The following pipeline examples install dependencies, cache dependencies, and build and test an Android app.
This pipeline uses Harness Cloud build infrastructure and Cache Intelligence.
If you copy this example, replace the placeholder values with appropriate values for your code repo connector, repository name, and other applicable values. Depending on your project and organization, you may also need to replace projectIdentifier and orgIdentifier.
This pipeline uses a Kubernetes cluster build infrastructure and Save and Restore Cache from S3 steps.
If you copy this example, replace the placeholder values with appropriate values for your code repo connector, repository name, and other applicable values. Depending on your project and organization, you may also need to replace projectIdentifier and orgIdentifier.
Next steps
Now that you have created a pipeline that builds and tests an Android app, you could:
Create triggers to automatically run your pipeline.
Add steps to build and upload artifacts.
Add a step to build and push an image to a Docker registry.
Last updated
Was this helpful?