CI/CD for React Native: Building Debug APKs with GitHub Actions
Feb 22, 2025
Are you looking for a React Native freelancer?
Email Me to Get StartedAs developers, we strive to automate as much as possible, minimizing manual tasks. Furthermore, when working in large teams, communicating the APK build process can be challenging, and waiting for builds can be time-consuming. In my React Native project, I've implemented an automation using GitHub Actions that builds a debug APK with every push to the main branch, facilitating easy sharing with clients.
If you're unfamiliar with GitHub Actions, this quickstart is a great resource: GitHub Docs Quickstart for GitHub Actions [TLDR: GitHub Actions automates software workflows directly within your GitHub repository, triggering actions through events like code pushes and pull requests]
Begin by creating your GitHub Actions workflow. You can either navigate to the 'Actions' tab in your repository or create a .github/workflows/create-apk-debug.yml
file.
Now, let's dive into the code!
--
This sets the name of the workflow. It is displayed in the GitHub Actions tab of your repository. In this case, the workflow is named "Build Android App".
name: "Build Android App"
This sets the name of the specific run of the workflow. The ${{ github.actor }}
is a placeholder that gets replaced with the username of the person who triggered the workflow. The full run name will be something like "username build Android Debug App using Github Actions".
run-name: ${{ github.actor }} build Android Debug App using Github Actions
Trigger, specific branches on push (for our examples is main)
on:
push:
branches:
- main
Setup our environment
# Defines a collection of jobs to be run as part of the workflow.
jobs:
build:
# Specifies the type of runner to use. In this case, it uses an Ubuntu 24.04 runner.
runs-on: ubuntu-24.04
steps:
# This step uses the actions/checkout@v4 action to check out the repository's code so that subsequent steps can access it.
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Java
uses: actions/setup-java@v4
with:
java-version: '20'
distribution: "adopt"
cache: "gradle"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
# Action to validate the Gradle Wrapper files, ensuring they have not been tampered with and are safe to use.
- name: Validate Gradle
uses: gradle/actions/wrapper-validation@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22'
And now we add the react native commands to build the debug apk as we do in our terminal
- name: Run Yarn Install
run: |
npm install -g yarn
yarn install
- name: Build App
run: |
cd android && ./gradlew assembleDebug && cd ../
Final, we must upload our apk
- name: Upload APK to Artifacts
uses: actions/upload-artifact@v4
with:
# This sets the name of the artifact. The artifact will be named "app" when it is uploaded to GitHub.
name: app
# This specifies the path to the APK file(s) to be uploaded. The wildcard *.apk ensures that any APK file in the specified directory will be uploaded. This is useful if the APK filename changes with each build.
path: ./android/app/build/outputs/apk/debug/*.apk
# This sets the number of days the artifact will be retained. In this case, the artifact will be kept for 7 days before being automatically deleted.
retention-days: 7
The final code!
name: "Build Android App"
run-name: ${{ github.actor }} build Android Debug App using Github Actions
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Java
uses: actions/setup-java@v4
with:
java-version: '20'
distribution: "adopt"
cache: "gradle"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Validate Gradle
uses: gradle/actions/wrapper-validation@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Run Yarn Install
run: |
npm install -g yarn
yarn install
- name: Build App
run: |
cd android && ./gradlew assembleDebug && cd ../
- name: Upload APK to Artifacts
uses: actions/upload-artifact@v4
with:
name: app
path: ./android/app/build/outputs/apk/debug/*.apk
retention-days: 7
git commit, push and we done!
Now, every time you push to the main branch, GitHub Actions will build a debug APK and upload it as an artifact.
P.S To build a release APK, you'll need to add sensitive environment variables as GitHub Secrets to your workflow, modify the build command to generate a release APK, and then upload the resulting /release/ APK artifact.
I hope this guide helps you automate your React Native APK builds. If you have any questions or need help, feel free to reach out to!