Files
flutter-sunset-alarm/compile.sh
T
2026-10-01 20:14:22 -07:00

122 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# 20260913 - Hyperling
# Build the project and add the output to a releases folder.
## Setup ##
DIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
## Functions ##
function log {
echo -e "\n $@ \n"
}
function clean_flutter {
log "Cleaning..."
flutter clean
echo "Done!"
}
## Variables ##
app_details="$DIR/pubspec.yaml"
name=""
for i in `grep name $app_details`; do
name="$i"
done
name="${name// /_}"
version=""
for i in `grep version $app_details`; do
version="$i"
done
version="${version// /_}"
if [[ -z $name || -z $version ]]; then
echo "ERROR: Could not retrieve name or version. name='$name' version='$version'"
exit 1
fi
RELEASE="release/$name-$version"
echo "Running for '$RELEASE'."
BUILD_OPTIONS=(
--release
--obfuscate
--split-debug-info=./debug-info/
--extra-gen-snapshot-options="--strip"
)
## Main ##
clean_flutter
# Linux
log "Building Linux Bundle..."
set -x
flutter build linux ${BUILD_OPTIONS[@]}
set +x
log "- zip"
filename=$RELEASE.linux-bundle.zip
contents="build/linux/x64/release/bundle/"
if [[ -e $filename ]]; then
rm -v $filename
fi
zip -qr "$filename" "$contents"/*
ls -sh $filename
log "- tar"
filename=$RELEASE.tar
if [[ -e "$filename"* ]]; then
rm -v "$filename"*
fi
set -x
tar -c --zstd -f "${filename}.zst" -C "$contents" .
tar -cz -f "${filename}.gz" -C "$contents" .
tar -cJ -f "${filename}.xz" -C "$contents" .
set +x
ls -sh "$filename"* | sort -h
# Android
log "Building Universal APK..."
# Creates a generic (and large) app-release.apk
set -x
flutter build apk ${BUILD_OPTIONS[@]}
set +x
#log "Saving Universal APK..."
#apk="build/app/outputs/flutter-apk/app-release.apk"
#filename=`basename $apk`
#filename=${filename//app/${RELEASE}}
#if [[ -e $filename ]]; then
# rm -v $filename
#fi
#cp -v "$apk" "$filename"
#ls -sh "$filename"
log "Building Individual APKs..."
# Creates files such as build/app/outputs/flutter-apk/app-arm64-v8a-release.apk
set -x
flutter build apk ${BUILD_OPTIONS[@]} --split-per-abi
set +x
log "Saving APKs..."
for apk in `ls build/app/outputs/flutter-apk/app*release.apk`; do
#if [[ "$apk" == *"x86"* ]]; then echo "Skipping $apk" continue; fi
#log "APK: $apk"
filename=`basename $apk`
filename=${filename//app/${RELEASE}}
cp -v "$apk" "$filename"
ls -sh "$filename"
echo " "
done
# Finish
exit 0