https://clappia.gitbook.io/engineering/blogs/automating-the-releases-of-android-apps-to-playstore
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:
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.
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
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
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.
Automating the release process for Android apps using tools like AWS CodeBuild helps reduce manual work, ensures consistency, and speeds up release cycles. Key steps include automating code commits, building, testing, and publishing the app.
L374, 1st Floor, 5th Main Rd, Sector 6, HSR Layout, Bengaluru, Karnataka 560102, India
+91 96418 61031
3500 S DuPont Hwy, Dover,
Kent 19901, Delaware, USA
+1 (341) 209-1116
3500 S DuPont Hwy, Dover,
Kent 19901, Delaware, USA
+1 (341) 209-1116
L374, 1st Floor, 5th Main Rd, Sector 6, HSR Layout, Bengaluru, Karnataka 560102, India
+91 96418 61031