Simplify Android App Releases Using GitHub Actions, Amazon S3, and Email Alerts
Table of contents
- A. Introduction
- B. Why Automate the Android Release Process?
- C. Prerequisite for setting up Email and GitHub Secret
- I . Getting Your Gmail Email Address
- II . Generating an App Password for Gmail
- III . Setting Up GitHub Secrets
- D. Overview of the Automation Workflow
- 1. Setting Up the GitHub Actions Workflow
- 2. Configuring the Development Environment
- 3. Building the Android Release Bundle
- 4. Caching Gradle Packages
- 5. Uploading the Release Bundle to Amazon S3
- 6. Generating a Download Link
- 7. Sending an Email Notification
- E. Conclusion
A. Introduction
In modern software development, automation is not just a convenience—it's a necessity. As developers, we often face repetitive tasks that can be error-prone when done manually. Automating these tasks ensures consistency, saves time, and allows us to focus on what truly matters: building great software. In this blog post, we'll explore how to automate the process of building an Android release, uploading it to Amazon S3, and sending an email notification with the download link using GitHub Actions.
B. Why Automate the Android Release Process?
Releasing a new version of an Android app involves several steps, including building the app, testing it, and distributing it to users. Manually handling these tasks can lead to delays, mistakes, and inconsistencies. Automation helps:
Reduce Human Error: By automating repetitive tasks, we minimize the risk of mistakes.
Save Time: Automated processes run faster and free up developers to work on other tasks.
Ensure Consistency: Every build and release is handled in the same way, ensuring consistency across versions.
Improve Traceability: Automation provides a clear log of what was done, when, and by whom, making it easier to track changes and identify issues.
C. Prerequisite for setting up Email and GitHub Secret
To use Gmail for sending automated emails via GitHub Actions, you need to obtain your Gmail email address and a secure password. Here’s a detailed guide on how to get and set these up:
I . Getting Your Gmail Email Address
This is straightforward. Your Gmail email address is simply your Gmail username, e.g., yourusername@gmail.com
.
II . Generating an App Password for Gmail
If you're using a Google account with 2-Step Verification enabled (which is recommended for security), you’ll need to create an App Password. This is a special password that allows third-party applications to access your Google account securely.
Steps to Generate an App Password:
Sign in to Your Google Account:
- Go to Google Account Security and log in with your Gmail account.
Enable 2-Step Verification:
- If you haven’t enabled 2-Step Verification (2FA), you need to do this first. Go to the 2-Step Verification page and follow the instructions to set it up.
Create an App Password:
Once 2-Step Verification is enabled, go back to the App Passwords page.
You may need to sign in again.
Under "Select app," choose "Other (Custom name)" and enter a name like "GitHub Actions."
Click on "Generate."
Copy the App Password:
- Google will generate a 16-character password. Copy this password and save it securely. This is your
EMAIL_PASSWORD
that you’ll use in GitHub Secrets.
- Google will generate a 16-character password. Copy this password and save it securely. This is your
III . Setting Up GitHub Secrets
With your Gmail address and App Password, you can now set up the GitHub Secrets required for the workflow.
Steps to Add Secrets to GitHub:
Go to Your GitHub Repository:
- Open your GitHub repository where you want to set up the workflow.
Navigate to Settings:
- Click on the "Settings" tab of your repository.
Access Secrets:
- In the sidebar, click on "Secrets and variables" and then "Actions."
Add New Secrets:
Click on "New repository secret" to add each secret.
For
EMAIL_USERNAME
, enter your Gmail address (e.g.,yourusername@gmail.com
).For
EMAIL_PASSWORD
, enter the App Password you generated.
D. Overview of the Automation Workflow
We’ll create a GitHub Actions workflow that triggers on every push to the main
branch. This workflow will:
Checkout the repository to get the latest code.
Set up the development environment by installing Node.js, JDK 11, and the Android SDK.
Install dependencies needed to build the Android app.
Build the Android release bundle using Gradle.
Upload the release bundle to Amazon S3 for easy distribution.
Generate a secure download link for the uploaded file.
Send an email notification to stakeholders with the download link.
Let’s dive into the details of each step.
1. Setting Up the GitHub Actions Workflow
GitHub Actions allows us to automate workflows directly from our GitHub repository. We’ll start by defining a workflow that is triggered whenever there’s a push to the main
branch.
Here’s the initial setup:
name: Build Android Release, Upload to S3, and Email Link
on:
push:
branches:
- main
This section specifies that the workflow should run whenever code is pushed to the main
branch.
2. Configuring the Development Environment
a. Checking Out the Repository
The first step in the workflow is to check out the code from the repository:
- name: Checkout repository
uses: actions/checkout@v2
This step fetches the latest code so that we can work with the most up-to-date version of the project.
b. Setting Up Node.js
Next, we set up Node.js, which is essential for managing dependencies in most JavaScript-based projects:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
Here, we specify Node.js version 16. Adjust this version according to your project requirements.
c. Installing Dependencies
Once Node.js is set up, we install the project dependencies:
- name: Install dependencies
run: npm install
This command installs all the necessary packages listed in your package.json
.
d. Setting Up JDK 11
Android projects require Java, so we’ll set up JDK 11 using the setup-java
action:
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: "adopt"
cache: "gradle"
JDK 11 is specified as it’s widely used in Android development. The cache: "gradle"
option helps speed up builds by caching Gradle dependencies.
e. Installing Android SDK
To build the Android app, we need the Android SDK. We can set it up using the setup-android
action:
- name: Install Android SDK
uses: android-actions/setup-android@v2
This action installs the Android SDK and necessary build tools.
3. Building the Android Release Bundle
With the environment set up, we can now build the Android release bundle:
- name: Build Android release bundle
working-directory: android
run: |
./gradlew clean
./gradlew bundleRelease
This step navigates to the android
directory and runs Gradle commands to clean the project and build the release bundle. The release bundle (.aab
file) is the package that will be uploaded to S3.
4. Caching Gradle Packages
Caching helps speed up subsequent builds by saving Gradle dependencies:
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
This step caches the Gradle packages, reducing build times for future runs.
5. Uploading the Release Bundle to Amazon S3
Now that we have the release bundle, we need to upload it to Amazon S3 for distribution:
a. Setting the Upload Directory with Date and Time
First, we set an upload directory name based on the current date and time:
- name: Set upload directory with date and time
id: set_upload_dir
run: echo "UPLOAD_DIR=$(date +'%Y-%m-%d_%H-%M-%S')" >> $GITHUB_ENV
This step creates a unique directory name in the S3 bucket for each upload.
b. Uploading to S3
Next, we upload the release bundle to S3:
- name: Upload to S3
uses: jakejarvis/s3-sync-action@v0.5.1
with:
args: --follow-symlinks --delete
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'ap-south-1' # Change to your desired region
SOURCE_DIR: 'android/app/build/outputs/bundle/release'
DEST_DIR: "${{ env.UPLOAD_DIR }}/"
The jakejarvis/s3-sync-action
is used to sync files between the local directory and the S3 bucket. We specify the source directory (where the release bundle is located) and the destination directory in the S3 bucket.
6. Generating a Download Link
Once the file is uploaded, we generate a secure download link:
- name: Generate S3 download link
id: s3link
run: echo "S3_DOWNLOAD_LINK=https://${{ secrets.AWS_S3_BUCKET }}.s3.amazonaws.com/app-release.aab" >> $GITHUB_ENV
This step creates a URL that points to the uploaded file in S3, which we’ll include in the email notification.
7. Sending an Email Notification
Finally, we send an email notification with the download link to the relevant stakeholders:
- name: Send email with S3 link
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.EMAIL_USERNAME }}
password: ${{ secrets.EMAIL_PASSWORD }}
subject: "New Android Release Bundle"
body: "The Android release bundle has been uploaded. You can download it from the following link: ${{ env.S3_DOWNLOAD_LINK }}"
to: rivayatt2021@gmail.com
from: ${{ secrets.EMAIL_USERNAME }}
The dawidd6/action-send-mail
action is used to send the email. We configure it to use Gmail’s SMTP server, but you can adjust this to use any email provider you prefer.
E. Conclusion
Automating the Android release process with GitHub Actions, Amazon S3, and email notifications ensures a consistent, error-free workflow that saves time and improves reliability. With this setup, every push to your main
branch will trigger a build, upload the release to S3, and notify your team—all without any manual intervention.
This workflow can be further customized to fit your specific needs. For example, you could add steps to run tests before the build, deploy the app to a beta testing platform, or integrate with other services your team uses.
By automating these processes, you’re not just saving time; you’re ensuring that your releases are handled in a professional, reliable manner that scales with your project.
Feel free to share your thoughts or ask questions in the comments below. Happy automating!
Subscribe to my newsletter
Read articles from indranil chakraborty directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by