Automated Release for Android Using GitHub Actions
Last Updated :
11 Jun, 2024
Automating the release process for Android applications can significantly enhance efficiency, reduce manual errors, and ensure consistent delivery. GitHub Actions provides a powerful platform to automate workflows directly from your GitHub repository. This article will guide you through setting up an automated release pipeline for Android using GitHub Actions.
Why Use GitHub Actions for Automated Releases?
GitHub Actions allows you to automate, customize, and execute software development workflows right in your repository. With GitHub Actions, you can:
- Automate the build, test, and release process.
- Integrate with various tools and services.
- Trigger workflows based on events like pushes, pull requests, and releases.
- Ensure consistent and repeatable build environments.
Setting Up Your Android Project
Before diving into GitHub Actions, ensure your Android project is set up correctly with the necessary build configurations.
- Gradle Configuration: Ensure your
build.gradle
file is properly configured with all dependencies and plugins required for building your project. - Versioning: Use a versioning scheme in your
build.gradle
file to manage app versions.
Creating a GitHub Actions Workflow
- Create the Workflow File: Inside your GitHub repository, create a new directory called
.github/workflows
if it doesn't exist. Then, create a file named release.yml
within this directory. - Define the Workflow: Open the
release.yml
file and define your workflow. Below is an example of a workflow configuration:
name: Android Release
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: 11
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Sign APK
env:
KEYSTORE_PATH: ${{ secrets.KEYSTORE_PATH }}
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
./gradlew assembleRelease
jarsigner -verbose -sigalg SHA256withRSA -digestalg SHA-256 -keystore $KEYSTORE_PATH app/build/outputs/apk/release/app-release-unsigned.apk $KEY_ALIAS
zipalign -v 4 app/build/outputs/apk/release/app-release-unsigned.apk app/build/outputs/apk/release/app-release.apk
- name: Upload APK
uses: actions/upload-artifact@v2
with:
name: app-release.apk
path: app/build/outputs/apk/release/app-release.apk
Explanation of the Workflow
- Trigger: The workflow triggers on a push to the
main
branch. - Job: The
build
job runs on an ubuntu-latest
runner. - Steps:
- Checkout: Uses the
actions/checkout
action to check out the repository. - Set up JDK: Uses the
actions/setup-java
action to set up JDK 11. - Grant Permission: Grants execute permission to the
gradlew
script. - Build: Runs the Gradle build command to build the project.
- Sign APK: Uses environment variables stored in GitHub Secrets to sign the APK.
- Upload APK: Uses the
actions/upload-artifact
action to upload the signed APK as a build artifact.
Configuring Secrets
To securely store sensitive information like keystore paths and passwords, use GitHub Secrets.
- Add Secrets:
- Navigate to your repository on GitHub.
- Go to
Settings
> Secrets
> Actions
. - Add the following secrets:
KEYSTORE_PATH
KEYSTORE_PASSWORD
KEY_ALIAS
KEY_PASSWORD
When done with writing the workflow, commit the changes and go to the Actions tab, you'll see a workflow running.

When both the jobs i.e. Generate APK and Release APK shows green check, go to Code and on the right side in the Releases section, you will see a release published with the name as the repository name happened with v1.

Best Practices
- Modularize Workflows: Break down your workflows into reusable components and actions.
- Secure Secrets: Always use GitHub Secrets for sensitive information.
- Monitor Workflows: Regularly monitor and maintain your workflows to ensure they run efficiently.
- Test Locally: Test your build and release processes locally before integrating them into GitHub Actions.
Conclusion
Automating the release process for your Android applications using GitHub Actions can significantly streamline your workflow and ensure consistent, reliable builds. By following the steps outlined in this article, you can set up a robust CI/CD pipeline that automates the build, sign, and release process, allowing you to focus more on developing new features and less on manual tasks. Embrace the power of automation and take your Android development workflow to the next level with GitHub Actions.
Similar Reads
Flutter - Building and Releasing APK using GitHub Actions Github Actions is a Github tool that allows users to create CI/CD pipelines directly in a Github project instead of going to a third-party website. It assists us in developing, testing, and releasing our project very conveniently. In this article, we're going to build a workflow for our Flutter proj
3 min read
Basic CI Workflow For Android using GitHub Actions Continuous integration (CI) is a software development process in which the team members can integrate their work. For Android developers, setting up a CI pipeline can greatly enhance productivity and code quality. GitHub Actions, a powerful automation tool integrated into GitHub, provides an excelle
2 min read
How to Set Up a CI Pipeline for Ktor Using GitHub Actions? In this article, we'll look at how to use GitHub Actions to create a robust and effective Continuous Integration (CI) pipeline for Ktor applications. Developers have a great foundation to construct high-performance server-side apps thanks to Ktor, a versatile and lightweight Kotlin framework for bui
6 min read
How to Upload Android APK to Testers Group in Firebase Using GitHub Actions? Testing is always required whenever we build an app to ensure it functions properly in production. It might be time-consuming and inconvenient to send the application to the testers every time new code is merged into the codebase. So to solve this problem, CD pipelines can be used to deliver the sof
3 min read
Microsoft Azure - Using Github Action in Azure App Service In this article, we will learn how to use GitHub Actions from Azure App Service. GitHub Actions enables us to automate builds and deployments which results in better quality software. For the purpose of demonstration, let's use it from this Azure App Service Web App that we've already created. This
2 min read
Spring Boot - Continuous Integration Using GitHub Actions Let's say we have two or more developers who are merging code into a single repository. There can be issues in merging code from different developers. So the Continuous Integration tools help in solving not just that but many other things like: Run an automated build after successful merging (like b
3 min read