CI/CD for Android

Hint

📚 Learn more about Android action features, integrations and alternatives.

With Buddy, you can create a pipeline that builds, tests, and deploys Android applications on a push to Git. The configuration is super simple and takes 10 to 15 minutes.

Image loading...Example Android delivery pipelineExample Android delivery pipeline

1. Select your Git repository

For the purpose of this guide, we created a simple project in Android Studio. The project was pushed to a Git repository to allow Buddy to access its files.

Image loading...Example Android Studio projectExample Android Studio project

Buddy supports all popular Git hosting providers, including GitHub, Bitbucket, and GitLab. You can also use your own private Git server, or host code directly on Buddy:

Image loading...Supported Git providersSupported Git providers

Here's how the project looks in the Code tab:

Image loading...Repository preview in BuddyRepository preview in Buddy

2. Add a new delivery pipeline

With the project attached, we can configure the deployment pipeline. Enter the pipeline's name, select the trigger mode, and define the branch from which Buddy should fetch your code:

Image loading...Exemplary pipeline settingsExemplary pipeline settings

Hint

Trigger modes

  • Manual (on click) — recommended for Production
  • On push (automatic) — recommended for Development
  • Recurrently (on time interval) — recommended for Staging/Testing
Success
Event-based triggers allow you to run pipelines whenever a push is made to any branch in the repository, or whenever a branch, tag or a pull request is created or deleted. Image loading...On event pipeline trigger modeOn event pipeline trigger mode

3. Add actions

In this example, we'll add 4 actions that will perform the following tasks:

  • Build your Android application
  • Sign app with your key
  • Upload APK to Google Play
  • (Optional) Send notification to Slack

3.1 Build your Android application

Success
Build actions in Buddy are run in isolated containers run from official Docker images. When the pipeline is run, Buddy pulls the container, runs build commands, and shares the results in the pipeline filesystem with deployment actions.

Look up and click Build APK on the action list to add it to the pipeline:

Image loading...APK Build on action listAPK Build on action list

The Run tab lets you determine the commands to execute. The default commands are:

export ANDROID_HOME="/opt/android/sdk"
export PATH=$PATH:/opt/android/sdk/cmdline-tools/tools/bin
if [ ! -d "$ANDROID_HOME/cmdline-tools" ]; then
 curl -o sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip
 unzip sdk.zip
 rm sdk.zip
 mkdir "$ANDROID_HOME/cmdline-tools"
 mv cmdline-tools "$ANDROID_HOME/cmdline-tools/tools"
 yes | "$ANDROID_HOME/cmdline-tools/tools/bin/sdkmanager" --licenses
fi

chmod +x gradlew
#./gradlew assembleDebug
./gradlew assembleRelease$$$$$$$$$$$$$$

Image loading...APK Build action configurationAPK Build action configuration

Once you add the action, you can run the pipeline and check the logs if everything has passed in order:

Image loading...Android build logsAndroid build logs

3.2 Sign your application (APK)

Success
To configure the signing action, you need the Google Play upload key, password, and key store path.
Warning
We strongly advise against keeping the key in the repository. Instead, we recommend saving it as an asset in Buddy, which is much more secure.

To save the upload key in Buddy, switch to the Variables tab and click Add variable → Asset:

Image loading...Adding new assetAdding new asset

Configure the asset details:

  • enter the name – you will use it in the signing action as the $ASSET_ID
  • upload the key from your disk
  • make sure that the asset is allowed to be copied to action containers

Image loading...Asset configurationAsset configuration

With the key safely stored, you can now look up the Sign APK on the action list:

Image loading...Sign APK on action listSign APK on action list

Add the action to the pipeline and fill the main tab with required data:

  • APK to sign path: the path in the pipeline filesystem with your APK build
  • Key store path: the $ASSET_ID of the key that you saved in Buddy
  • Key store password: the password that you provided when creating the key

Image loading...Sign APK action configurationSign APK action configuration

3.3 Deploy APK to Google Play

Now, we can deploy the signed package to the Google store. Before adding the publishing action, however, you need to configure a few things in Google:

  1. Enable Google Play Android Developer API in your gcloud project:

    Image loading...Google Play Android Developer APIGoogle Play Android Developer API

  2. Create a service account in Google Cloud with a private key in the .json format:

    Image loading...Creating service account in GoogleCreating service account in Google

    Image loading...Saving key as JSONSaving key as JSON

  3. Invite the created user to your Google Play account and grant them Releases permissions to allow publishing to Google Play:

    Image loading...Granting permissions to Google PlayGranting permissions to Google Play

With everything prepared, you can finally add the Google Play Publish APK action to the pipeline:

Image loading...Google Play Publish APKGoogle Play Publish APK

The action requires an integration with Google Play Store. When adding the integration, upload the key generated in the associated service account:

Image loading...Adding Google Play Store integrationAdding Google Play Store integration

In the action details, select the signed package in the pipeline filesystem, define the development track (alpha, beta, production, etc.), and enter the app ID:

Image loading...Google Play Publish APK action configurationGoogle Play Publish APK action configuration

Success
Congratulations! You have just automated the entire Build → Sign → Publish process. 😎🎉

3.4 (Optional) Send notification to Slack

You can configure Buddy to send your team a message after a new package is released. In this example we'll use Slack:

Image loading...Notification actionsNotification actions

Hint
If you add this action in the On Failure tab, Buddy will only send the message if something goes wrong with your build or deployment. Image loading...On failure notificationOn failure notification
Success
Bear in mind that this article is only a brief example of what Buddy can do. You can create additional pipelines for staging and production environments, integrate with your favorite services (AWS, Google, Azure), trigger tests on pull requests, build Docker images, and push them to the registry—the possibilities are unlimited.
Tip
If you want us to create a delivery pipeline for your project, drop a line to support@buddy.works – we'll be happy to help!
Last update:
Sep 23, 2024