Learn how to automate building AndroidAPS using GitHub actions. If you don't know what these are, please just continue using the standard build instructions.
WARNING: Do NOT make your GitHub repository public and do NOT share the build artifacts with anyone. AndroidAPS prohibits distributing APKs and you will face personal responsibility if somebody else uses the artifact and encounters issues.
Create a private repository in GitHub. Create a directory .github/workflows
and add a file android-build.yml
with the following content:
name: Android Build
on:
workflow_dispatch:
inputs:
tag:
description: "Version to build"
required: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout AndroidAPS ${{ github.event.inputs.tag }}
uses: actions/checkout@v4
with:
repository: "nightscout/AndroidAPS"
ref: ${{ github.event.inputs.tag }}
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: "21"
distribution: "temurin"
- name: Setup Android SDK
uses: android-actions/setup-android@v3
with:
packages: ""
- name: Accept Android SDK licenses
run: yes | sdkmanager --licenses
- name: Install Android SDK Build-Tools
run: sdkmanager "build-tools;29.0.3"
- name: Build with Gradle
run: ./gradlew --no-daemon app:assembleFullRelease
- name: Sign APK
uses: r0adkll/sign-android-release@v1
with:
releaseDirectory: app/build/outputs/apk/full/release
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
alias: ${{ secrets.ALIAS }}
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_PASSWORD }}
- name: Copy APK
run: |
cp app/build/outputs/apk/full/release/app-full-release-unsigned-signed.apk app/build/outputs/apk/full/release/app-full-release-signed.apk
- name: Release APK
uses: softprops/action-gh-release@v2
with:
name: AndroidAPS ${{ github.event.inputs.tag }}
tag_name: ${{ github.event.inputs.tag }}
token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
files: |
app/build/outputs/apk/full/release/app-full-release-signed.apk
Commit the file to the repository. This file will build the AndroidAPS APKs.
In GitHub developer settings, create a new fine-grained token with these permissions:
- "Contents" repository permissions (write)
- "Workflows" repository permissions (write)
You can make the key never expire, or let it expire and renew it when it expires. Add a secret to the repository with the key CUSTOM_GITHUB_TOKEN
and the value of the token.
You need a signing key to sign the APK. Create a new key with Android Studio as explained in the official documentation. Convert the key to base64 and add it as a secret to the repository with the key SIGNING_KEY
:
openssl base64 < keystore.jks |tr -d '\n' | tee keystore.base64.txt
Also add the alias, keystore password, and key password as secrets to the repository with the keys ALIAS
, KEY_STORE_PASSWORD
, and KEY_PASSWORD
.
Go to the Actions tab in your repository, select the "Android Build" action and click the "Run workflow" button. Enter the version to build, which is the tag of the AndroidAPS repository you want to build. Use the latest tag or any other tag. The action will build the APK and create a release with the APK attached.
The free GitHub runner runs very slowly. Building takes about 40 minutes. Spend money to sign up for a faster runner. Many providers offer GitHub runners - I used Ubicloud, which offers the ubicloud-standard-8
runner that completes the build in about five minutes. One build costs about two cents.