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.
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.
This section describes the high-level setup of the automation process.
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.
To create a CodeBuild project, we use CloudFormation instead of the AWS Console. Here's an example snippet from the template.yaml file:
Description: Code Release for MobileApp
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.
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.
# 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
The build phase contains commands to build the Android app and publish it to PlayStore. Here are the relevant 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
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.
Automate your Android app releases to the Play Store with ease.Get Started - It's free