[deployment] trying to fix android github build #181
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: [push, pull_request] | |
# all from flutterust MIT licensed | |
# | |
# name is (urlencode) connected to README.md svg badge (change it there as well) | |
name: Android Build | |
jobs: | |
build: | |
name: Compile and Build - Android | |
runs-on: ubuntu-20.04 | |
steps: | |
# use to your like https://github.com/marketplace?type=actions | |
# #################### build conditions | |
- name: vtag variable | |
shell: bash | |
run: echo "vtag=$(echo ${GITHUB_REF#refs/tags/} | awk '/v([0-9]+\.)+[0-9]+/{print $0}')" >> $GITHUB_ENV | |
- name: Ensure UTF-8 console | |
shell: bash | |
run: export LANG=C.UTF-8 | |
# due to https://github.com/rust-lang/rust/issues/63939#issuecomment-665952545 | |
- name: Install musl-tools | |
shell: bash | |
run: sudo apt-get -y install musl-tools gcc-aarch64-linux-gnu libc6-dev-arm64-cross qemu-user | |
- name: Extractor for vtag env | |
id: extract_tag | |
shell: bash | |
run: echo "{tag}==${{ env.vtag }}" >> $GITHUB_OUTPUT | |
- name: Release | |
if: steps.extract_tag.outputs.tag != null | |
shell: bash | |
run: echo "Building release" | |
# ##################### setup build environment | |
- name: Cache LLVM and Clang | |
id: cache-llvm | |
uses: actions/cache@v2 | |
with: | |
path: ${{ runner.temp }}/llvm/11.0 | |
key: llvm-11.0 | |
- name: Install LLVM and Clang | |
uses: KyleMayes/install-llvm-action@v1 | |
with: | |
version: "11.0" | |
directory: ${{ runner.temp }}/llvm/11.0 | |
cached: ${{ steps.cache-llvm.outputs.cache-hit }} | |
- name: Checkout sources | |
uses: actions/checkout@v2 | |
- name: Install Rust Toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
components: rustfmt | |
- name: Install WASM Target | |
run: rustup target add wasm32-unknown-unknown | |
- name: Cache Cargo | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
~/.cargo/bin | |
target/aarch64-linux-android | |
target/armv7-linux-androideabi | |
target/x86_64-linux-android | |
target/i686-linux-android | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
# todo: some time again, test https://github.com/actions-rs/install | |
- name: Install Cargo Tools (cargo-make, v0.32) | |
uses: actions-rs/cargo@v1 | |
continue-on-error: true | |
with: | |
command: install | |
args: cargo-make --version ^0.32 | |
- name: Install Cargo Tools (cbindgen, v0.15) | |
uses: actions-rs/cargo@v1 | |
continue-on-error: true | |
with: | |
command: install | |
args: cbindgen --version ^0.15 | |
- name: Install Cargo Tools (dart-bindgen, v0.1) | |
uses: actions-rs/cargo@v1 | |
continue-on-error: true | |
with: | |
command: install | |
args: dart-bindgen --features cli --version ^0.1 | |
- name: Clone repository | |
uses: actions/checkout@v4 | |
- name: Set up Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: stable | |
flutter-version: 3.19.0 | |
- run: flutter --version | |
# ANDROID_NDK_HOME is adapted to where "Setup Android SDK" decides (due to github logs) | |
# to install it to ... | |
- name: NDK checkou | |
uses: actions/checkout@v3 | |
- name: NDK setup | |
uses: nttld/setup-ndk@v1 | |
id: setup-ndk | |
with: | |
ndk-version: r21e | |
add-to-path: true | |
link-to-sdk: true | |
local-cache: true | |
- run: echo $ANDROID_NDK_HOME | |
env: | |
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} | |
- name: Install Android Targets | |
shell: bash | |
run: rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android | |
# cargo-ndk currently has version 2.1.0 but for make android-dev | |
# this version doesn't work, but 1.0.0 did | |
# todo: look for changes to stay updated | |
- name: Downgrade cargo-ndk (cargo-ndk, v1.0.0) | |
shell: bash | |
run: cargo install cargo-ndk --version 2.12.6 | |
# 2nd helper to find problems | |
- name: find more | |
continue-on-error: true | |
shell: bash | |
run: ls $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/ || echo "dir not found" | |
# 3rd helper to ndk helper files | |
- name: find ndk files | |
continue-on-error: true | |
shell: bash | |
run: ls -R $ANDROID_NDK_HOME/toolchains || echo "this dir not found" | |
# ############### Release/Debug build dependent | |
- name: Run cargo make android - Debug | |
if: steps.extract_tag.outputs.tag == null | |
uses: actions-rs/cargo@v1 | |
continue-on-error: false | |
with: | |
command: make | |
args: android-dev | |
- name: Build APK (x86_64, Debug) | |
if: steps.extract_tag.outputs.tag == null | |
run: flutter build apk --debug --no-sound-null-safety | |
- name: Run cargo make android - Release | |
if: steps.extract_tag.outputs.tag != null | |
uses: actions-rs/cargo@v1 | |
continue-on-error: false | |
with: | |
command: make | |
args: android-arm --profile release | |
# help from https://dev.to/cddelta/signing-flutter-android-apps-for-release-in-github-actions-2892 | |
- name: Create Key from github secret for Release | |
if: steps.extract_tag.outputs.tag != null | |
run: echo ${{ secrets.SIGNING_KEY }} | base64 -d > android/key.jks | |
# https://flutter.dev/docs/deployment/android#signing-the-app | |
- name: Build APK (arm64, Release) | |
if: steps.extract_tag.outputs.tag != null | |
# https://flutter.dev/docs/perf/app-size | |
run: flutter build apk --release --target-platform android-arm64 --obfuscate --split-debug-info=build/dart-debug-info/${{ steps.extract_tag.outputs.tag }}/android | |
env: | |
KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} | |
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
ALIAS: ${{ secrets.ALIAS }} | |
KEY_PATH: android/key.jks | |
# ####################### upload intermediate result dependent if release in text or tagged | |
# https://github.com/marketplace/actions/upload-files-to-a-github-release | |
- name: Upload Release Asset | |
if: steps.extract_tag.outputs.tag != null | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: ./build/app/outputs/flutter-apk/app-release.apk | |
asset_name: adbfflutter-${{ steps.extract_tag.outputs.tag }}-arm64.apk | |
tag: ${{ steps.extract_tag.outputs.tag }} | |
overwrite: true |