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.
- Create a
.github/workflows
directory in your project's root. - Create a file called
app-android.yml
with the following content:
_53name: Build Android_53_53on:_53 push:_53 branches: [ "main" ]_53 pull_request:_53 branches: [ "main" ]_53_53jobs:_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:
_10keytool -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:
_10base64 -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.