Automating the releases of Android Apps to PlayStore

Technology
Automating the releases of Android Apps to PlayStore

Automating the releases of Android Apps to PlayStore

Technology
July 10, 2023
10 Mins

The process of generating and releasing Android apps to the Play Store can be time-consuming and error-prone, especially when dealing with multiple white-labeled apps and frequently changing development environments. To overcome these challenges, automation becomes crucial. In this technical blog, we will explore how we have automated the process of generating and releasing Android apps to the Play Store using AWS CodeBuild. We'll discuss the requirements, challenges, and step-by-step implementation using AWS CodeBuild.

Automating the releases of Android Apps to PlayStore

Why is Automation required?

  1. Efficient generation of multiple Apps: Automating the process of generating white-labeled apps with unique configurations reduces development effort and ensures consistency across different clients or brands.
  2. Reliable Build Environments: Automation eliminates the risk of errors caused by changing development environments, ensuring that APK generation remains consistent and successful.
  3. Accelerated Release Cycles: Automation enables faster releases, allowing for frequent updates and quicker deployment of new features and bug fixes.
  4. Enhanced Transparency: Automation provides clear visibility into the release process, enabling stakeholders to track progress, manage timelines, and align business goals effectively.
  5. Scalability and Consistency: Automation allows for the scalable generation and release of multiple apps, ensuring consistent quality and adherence to standards.

       https://clappia.gitbook.io/engineering/blogs/automating-the-releases-of-android-apps-to-playstore

Challenges in automating the process

  1. Cross-Account configurations: We have two AWS Accounts in picture. The codebase resides in a development AWS account, but the white labeled app configurations are stored in the production account.
  2. CLI-based Approach: Automating the process requires shifting from Android Studio to a CLI-based process.
  3. Continuous Maintenance: Automated processes require continuous maintenance to keep pace with updates in tools, libraries, and dependencies, ensuring compatibility and preventing build failures.

About AWS CodeBuild

AWS CodeBuild is a fully managed continuous integration service provided by AWS that compiles source code, runs tests, and produces deployable artifacts. It provides a build environment defined in a build specification file (buildspec.yml), which outlines the steps required to build the project.

CodeBuild can be connected to AWS CodeCommit so that any code check-ins to CodeCommit automatically triggers CodeBuild without the need of any manual intervention.

Multiple runtime environments and images are supported by CodeBuild. The detailed list can be found here.

High-level Setup

This section describes the high-level setup of the automation process.

Automating the releases of Android Apps to PlayStore

The setup involves two AWS accounts: the Dev Account, where developers commit the code, and the Prod Account, where the White-labeled App Configs are stored.

Step 1: Code Commit Developers commit the code to AWS CodeCommit, which serves as the version control repository for the project.

Step 2: CodeBuild TriggerAWS CodeBuild is configured to monitor the CodeCommit repository for changes. When developers commit code changes, CodeBuild is automatically triggered.

Step 3: Build Environment SetupCodeBuild starts a server using the specified configuration and installs necessary dependencies, including android-sdk-tools and other required components.

Step 4: Fetching White-Labeled App ConfigsCodeBuild fetches the White-labeled App Configs, such as the app name, icon, splash screen, and workplace preferences, from the Prod Account. Cross-account access is facilitated using AWS Security Token Service (STS) to ensure secure retrieval of the configurations.

Step 5: APK and App Bundle GenerationCodeBuild executes commands to trigger the generation of APK (Android Application Package) and App Bundle, which are the compiled and signed versions of the Android app.

Step 6: Publishing to Google Play StoreFinally, CodeBuild executes the necessary commands to publish the generated APK or App Bundle to the Google Play Store, making the app available for distribution to users.

Details about each step

Creating the CodeBuild Project

To create a CodeBuild project, we use CloudFormation instead of the AWS Console. Here's an example snippet from the template.yaml file:

MobileApp:
 Type: AWS::CodeBuild::Project
 Properties:
   Name: MobileApp-Prod
   Description: Code Release for MobileApp
   Artifacts:
     Type: NO_ARTIFACTS
   Environment:
     Type: LINUX_CONTAINER
     ComputeType: BUILD_GENERAL1_MEDIUM
     Image: aws/codebuild/standard:5.0
   Source:
     BuildSpec: buildspec.prod.yml
     Location: https://git-codecommit.ap-south-1.amazonaws.com/v1/repos/MobileApp
     Type: CODECOMMIT
   SourceVersion: refs/heads/master

The template defines the Source Code location of the MobileApp repository, in our case is in AWS CodeCommit. Deploying this template auto generates a CodeBuild Project with Ubuntu standard:5.0 Image which supports NodeJS 14 runtime.

Installing dependencies in the CodeBuild Project

We had specified a buildspec.yml file in the above step. This file lists the commands needed to install the dependencies. We install the Android command-line tools which bring in Android’s build-tools, platform-tools and Gradle. Following is a snippet of the install section of the file.

install:
   commands:
# Set the Node.js version to 14
- n 14
# Download the Android command-line tools archive, extract and install
- export ANDROID_TOOLS_FILENAME="commandlinetools-linux-8512546_latest.zip"
- wget https://dl.google.com/android/repository/$ANDROID_TOOLS_FILENAME -P ~ > /dev/null
- unzip ~/$ANDROID_TOOLS_FILENAME -d ~ > /dev/null 2>&1
- mkdir -p /usr/local/android-sdk-linux/cmdline-tools
- mv ~/cmdline-tools /usr/local/android-sdk-linux/cmdline-tools/latest
# set the PATH variables
- export PATH=$PATH:/usr/local/android-sdk-linux/cmdline-tools/latest:/usr/local/android-sdk-linux/cmdline-tools/latest/bin:/usr/local/android-sdk-linux/platform-tools
- export ANDROID_SDK_ROOT=/usr/local/android-sdk-linux
# Accept the Android SDK licenses and install platform-tools and build-tools
- yes | sdkmanager --licenses > /dev/null
- sdkmanager "platform-tools" "platforms;android-31" > /dev/null
- sdkmanager "build-tools;31.0.0" > /dev/null
# Install your npm dependencies
- npm i
# Get the script to use STS to set up the AWS credentials and get access to the Prod Account
- aws s3 cp s3://clappia/aws-profile-setup.sh ./
- chmod +x aws-profile-setup.sh
- . ./aws-profile-setup.sh

Build Commands

The build phase contains commands to build the Android app and publish it to PlayStore. Here are the relevant commands:

build:
  commands:
# Run your local builds to compile, minify and generate prod distributions
- npm build
# Generate the Release APK and App Bundle files
- ./gradlew bundle
- ./gradlew assembleRelease
# Publish the Bundle to Google Play Store - ./gradlew publishReleaseBundle --artifact-dir
../builds

Conclusion

Automating the process of generating and releasing Android apps to the Play Store significantly reduces development effort and streamlines the release cycle. By leveraging AWS CodeBuild, we can achieve a seamless and efficient workflow, ensuring faster updates, increased transparency, and better management of white-labeled apps. Embracing automation in app release processes is a crucial step toward optimizing development efforts and delivering a superior user experience.

FAQ

Automate your Android app releases to the Play Store with ease.
Automate your Android app releases to the Play Store with ease.Get Started - It's free