Skip to content

'android' branch update: Android Vector Math Preservation, Multi-LLM Engine Integration, Token Counter & CI Release Fixes #19

'android' branch update: Android Vector Math Preservation, Multi-LLM Engine Integration, Token Counter & CI Release Fixes

'android' branch update: Android Vector Math Preservation, Multi-LLM Engine Integration, Token Counter & CI Release Fixes #19

Workflow file for this run

name: Android
# The APK is built on every push to the Android branch and on pull requests, so
# a broken build is visible before anyone tries to release. Publishing is a
# separate job that only a push or tag can reach.
#
# Tags are namespaced `android-v*` on purpose. `v*` belongs to the desktop
# build: release.yml triggers on it and app/update.py downloads
# PDFTranslate-windows.zip from whatever it finds there, so an Android release
# under `v*` would tell every installed Windows copy to update to an asset that
# does not exist.
on:
push:
branches:
- main
- feat/android-apk
- android-dev
tags:
- "android-v*"
pull_request:
paths:
- "android/**"
- ".github/workflows/android-build.yml"
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: android
env:
GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4096m -XX:+UseG1GC"
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
# gradle-wrapper.jar is a binary that arrived through a pull request.
# Check it against Gradle's published checksums before running it.
- name: Validate the Gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
- uses: gradle/actions/setup-gradle@v4
- name: Make gradlew executable
run: chmod +x gradlew
- name: Read the version name
id: version
run: echo "version=$(./gradlew -q printVersionName)" >> "$GITHUB_OUTPUT"
- name: Unit tests and lint
run: ./gradlew test
# The debug APK is signed with the runner's throwaway debug key, which is
# useless for distribution but is the only build installable on a phone
# before the release keystore secrets exist.
- name: Build the debug APKs
run: ./gradlew assembleDebug
# A release APK signed with a throwaway debug key cannot be updated over,
# so the keystore comes from repository secrets. Without them the release
# build stays unsigned and the publish job below refuses to run.
- name: Decode the release keystore
id: keystore
env:
KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
run: |
if [ -z "$KEYSTORE_BASE64" ]; then
echo "No ANDROID_KEYSTORE_BASE64 secret; skipping signed release APK."
echo "signed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
printf '%s' "$KEYSTORE_BASE64" | tr -d '[:space:]' | base64 -d > "$RUNNER_TEMP/release.jks"
if ! keytool -list -keystore "$RUNNER_TEMP/release.jks" \
-storepass "$KEYSTORE_PASSWORD" >/dev/null 2>&1; then
echo "The keystore decoded but will not open. Check ANDROID_KEYSTORE_PASSWORD." >&2
exit 1
fi
echo "signed=true" >> "$GITHUB_OUTPUT"
- name: Build the release APKs
if: steps.keystore.outputs.signed == 'true'
env:
ANDROID_KEYSTORE_PATH: ${{ format('{0}/release.jks', runner.temp) }}
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
run: ./gradlew assembleRelease
- name: Remove the keystore
if: always()
run: rm -f "$RUNNER_TEMP/release.jks"
- name: Collect APK artifacts
run: |
mkdir -p apks_dist
version="${{ steps.version.outputs.version }}"
find app/build/outputs/apk -name "*.apk" | while read -r apk_file; do
dir=$(dirname "$apk_file")
flavor=$(echo "$dir" | awk -F'/' '{print $(NF-1)}')
build_type=$(echo "$dir" | awk -F'/' '{print $NF}')
dest_name="PDFTranslate-android-${version}-${flavor}-${build_type}.apk"
cp "$apk_file" "apks_dist/${dest_name}"
echo "Collected APK: apks_dist/${dest_name}"
done
ls -la apks_dist
- uses: actions/upload-artifact@v4
with:
name: PDFTranslate-android-apks
path: android/apks_dist/*.apk
if-no-files-found: error
publish:
needs: build
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: PDFTranslate-android-apks
path: android-apks
- name: List downloaded APK artifacts
run: ls -la android-apks
- uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ startsWith(github.ref, 'refs/tags/android-v') && github.ref_name || 'android-dev-latest' }}
name: ${{ startsWith(github.ref, 'refs/tags/android-v') && format('Android {0}', needs.build.outputs.version) || 'Android Continuous Build' }}
prerelease: ${{ !startsWith(github.ref, 'refs/tags/android-v') }}
files: android-apks/*.apk
fail_on_unmatched_files: true