Building Android on self-hosted Linux GitHub Actions runners

Note that this guide was last updated on 07/07/21.

Last year, I had some trouble setting up Android builds on self-hosted GitHub Actions runners for smart-brocolli. This post serves to document this process.

  1. Provision a Linux VM. I will be using Ubuntu 20.04 on Azure.
  2. Install Flutter SDK.
  3. Add flutter to $PATH and run $ flutter doctor.
  4. Download Android command-line tools.
  5. Extract tools:
    $ sudo apt install unzip && unzip commandlinetools-linux-*.zip
  6. Set up Android directory:
    $ mkdir android-sdk && mkdir android-sdk/cmdline-tools && \
     mv cmdline-tools/ android-sdk/cmdline-tools/latest
  7. Add android-sdk/cmdline-tools/latest/bin/ to $PATH, set $ANDROID_HOME.
    export ANDROID_HOME=`pwd`/android-sdk
    export PATH="$PATH:`pwd`/flutter/bin:`pwd`/android-sdk/cmdline-tools/latest/bin"
  8. Install Java:
    $ sudo apt install openjdk-8-jdk
  9. Install Platform SDK and build-tools using sdkmanager, e.g.:
    $ sdkmanager --install "platforms;android-30"
    $ sdkmanager --install "build-tools;30.0.2"
  10. Review licenses:
    $ flutter doctor --android-licenses
  11. Run $ flutter doctor again.
    Ensure that a tick is given for Android Toolchain.
  12. Finally, add an appropriate GitHub Actions workflow.