Building and testing ODK Collect without Android Studio or Java

This is a post to help any devs who want to build ODK Collect in a consistent way, but may not regularly use Android Studio or Java.

Related to https://github.com/getodk/collect/pull/5928

I made a Github Gist that details how to run the test suite, check for linting errors, build and sideload APKs for testing. The post also details running the generated APK inside an emulated Android device, all using Docker:

Here is also an example Github workflow for building an ODK Collect APK via tag/release:

# Workflow to deploy custom builds on ODK Collect

name: 🔧 Build and Release

on:
  release:
    types: [published]

jobs:
  build_upload_apk:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    container:
        image: docker.io/cimg/android:2023.10.1

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Add Robolectric Deps
        run: ./download-robolectric-deps.sh

      - name: Compile Code
        run: ./gradlew assembleDebug

      - name: Install Github CLI
        run: |
          sudo apt update
          sudo apt install --no-install-recommends -y gh

      - name: Build & Upload APK
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          ./gradlew assembleSelfSignedRelease

          apk_path=$(find ./collect_app/build/outputs/apk/selfSignedRelease -name '*.apk' -type f)
          echo "Generated APK file: ${apk_path}"

          gh release upload ${{ github.event.release.tag_name }} "${apk_path}"