Skip to content

Instantly share code, notes, and snippets.

@anhartasman
Created February 6, 2025 11:51
Show Gist options
  • Save anhartasman/5a6d4d6dde839c26844e9fd5e721d733 to your computer and use it in GitHub Desktop.
Save anhartasman/5a6d4d6dde839c26844e9fd5e721d733 to your computer and use it in GitHub Desktop.
Build APK Sh
#!/bin/bash
# This script builds the Flutter APK and names it with a timestamp format while deleting the previous version
APK_DIR="build/app/outputs/apk/release/"
APK_PREFIX="makanmakan"
# Get the current timestamp in yy_MM_dd_hh_mm format
TIMESTAMP=$(date +"%y_%m_%d_%H_%M")
NEW_APK="${APK_PREFIX}_${TIMESTAMP}.apk"
FILE_PATH="${APK_DIR}${NEW_APK}"
# Delete any previous APKs matching the prefix
echo "Deleting previous APKs matching prefix '${APK_PREFIX}'..."
find "$APK_DIR" -name "${APK_PREFIX}_*.apk" -exec rm -f {} \;
# Build the Flutter APK
flutter build apk --release --no-tree-shake-icons
# Move the newly built APK and rename it
if [ -f "${APK_DIR}app-release.apk" ]; then
mv "${APK_DIR}app-release.apk" "$FILE_PATH"
echo "APK built and saved as $NEW_APK"
else
echo "Error: Flutter build did not generate an APK."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment