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.
- Provision a Linux VM. I will be using Ubuntu 20.04 on Azure.
- Install Flutter SDK.
https://flutter.dev/docs/get-started/install/linux#install-flutter-manually - Add flutter to
$PATH
and run$ flutter doctor
. - Download Android command-line tools.
https://developer.android.com/studio#command-tools - Extract tools:
$ sudo apt install unzip && unzip commandlinetools-linux-*.zip
- Set up Android directory:
$ mkdir android-sdk && mkdir android-sdk/cmdline-tools && \ mv cmdline-tools/ android-sdk/cmdline-tools/latest
- Add
android-sdk/cmdline-tools/latest/bin/
to$PATH
, set$ANDROID_HOME
.
e.g.export ANDROID_HOME=`pwd`/android-sdk export PATH="$PATH:`pwd`/flutter/bin:`pwd`/android-sdk/cmdline-tools/latest/bin"
- Install Java:
$ sudo apt install openjdk-8-jdk
- Install Platform SDK and build-tools using
sdkmanager
, e.g.:$ sdkmanager --install "platforms;android-30" $ sdkmanager --install "build-tools;30.0.2"
- Review licenses:
$ flutter doctor --android-licenses
- Run
$ flutter doctor
again.
Ensure that a tick is given for Android Toolchain. - Finally, add an appropriate GitHub Actions workflow.