Skip to main content

Building for Android

If you use GitHub to host your code then you can use GitHub Actions to build your app for Android. This is the first step in automating the deployment of your app to the Play Store.

The following tutorial shows you how you can create a workflow file which will be run when you commit code.

  1. Create a .github/workflows directory in your project's root.
  2. Create a file called app-android.yml with the following content:

_53
name: Build Android
_53
_53
on:
_53
push:
_53
branches: [ "main" ]
_53
pull_request:
_53
branches: [ "main" ]
_53
_53
jobs:
_53
build:
_53
name: Build AAB
_53
runs-on: ubuntu-latest
_53
steps:
_53
- name: Checkout source
_53
uses: actions/checkout@v4
_53
_53
- name: Setup java
_53
uses: actions/setup-java@v4
_53
with:
_53
distribution: 'zulu'
_53
java-version: '17'
_53
_53
- name: Setup Node.js
_53
uses: actions/setup-node@v4
_53
with:
_53
node-version: 20.x
_53
_53
- name: Install app dependencies
_53
run: npm install
_53
_53
- name: Build project app
_53
run: npm run build
_53
_53
- name: Capacitor sync
_53
run: npx cap sync
_53
_53
- name: Build app bundle
_53
run: cd android && ./gradlew bundle
_53
_53
- name: Extract Android signing key from env
_53
run: |
_53
echo "${{ secrets.KEYSTORE_BASE64 }}" > android/release.jks.base64
_53
base64 -d android/release.jks.base64 > android/release.decrypted.jks
_53
_53
- name: Sign build
_53
run: jarsigner -keystore android/release.decrypted.jks -storepass "${{ secrets.KEYSTORE_PASSWORD }}" -signedjar ./android/app/build/outputs/bundle/release/app-release-signed.aab ./android/app/build/outputs/bundle/release/app-release.aab dust
_53
_53
- name: Upload release bundle
_53
uses: actions/upload-artifact@v4
_53
with:
_53
name: app-release
_53
path: android/app/build/outputs/bundle/release/app-release-signed.aab
_53
retention-days: 60

This workflow has several variables that you need to setup in your repository secrets (In your GitHub repo go to Settings > Secrets & Variables > Actions > New repository secret):

Create a Service Account

Sign into the Google Cloud Platform Console

  • Go to APIs & Services > Credentials > Create Credentials > Service Account Key.

The Keystore File

If you do not have a keystore file you can create one using the following command:


_10
keytool -genkey -v -keystore keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias release

Follow the prompts and enter yes to save your key. You will be asked for a Keystore password which is used for the KEYSTORE_PASSWORD secret, an alias which will be used for the KEY_ALIAS secret and a Key password which is used for the KEY_PASSWORD secret.

Do not commit the keystore file to your repository (add to .gitignore).

To create the KEYSTORE_BASE64 secret run the following command:


_10
base64 -i keystore.jks | pbcopy

The contents of the keystore are now in the clipboard and you can paste it into the KEYSTORE_BASE64 secret.

Summary

The build process with GitHub Actions should now have all the required variables to build your application for Android.

The next tutorial shows how you can expand on this workflow to send the build to the Play Store.