Last active
October 20, 2024 12:07
-
-
Save Taosif7/0c0cf40274a654c9f3487c125c624ba4 to your computer and use it in GitHub Desktop.
A Bash Script to Copy flutter generated build outputs in a proper format
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
#!/bin/bash | |
# Check if pubspec.yaml file exists | |
if [ ! -f "pubspec.yaml" ]; then | |
echo "⚠️ Please run command in a Flutter project" | |
exit 1 | |
fi | |
# Get the value of "name: value" | |
projectName=$(awk '/name:/ {print $2}' pubspec.yaml) | |
# Get the value of "version: value" | |
version=$(awk '/version:/ {print $2}' pubspec.yaml) | |
IFS='+' read -ra versionParts <<< "$version" | |
buildName=${versionParts[0]} | |
buildNumber=${versionParts[1]} | |
# Check if the Assets exist | |
apkFound=false | |
aabFound=false | |
[ -f build/app/outputs/flutter-apk/*.apk ] && apkFound=true || apkFound=false | |
[ -f build/app/outputs/bundle/*.aab ] && aabFound=true || aabFound=false | |
if ! $apkFound && ! $aabFound; then | |
echo "⚠️ No assets found to copy. Please generate APK/AAB and run again" | |
exit 1 | |
fi | |
# Create filename format | |
desktopPath="$HOME/Desktop" | |
formattedDate=$(date +%m%d%y) | |
newFileName="$projectName"_v"$buildName"\("$buildNumber"\)_"$formattedDate" | |
# Copy APK | |
if $apkFound; then | |
cp build/app/outputs/flutter-apk/*.apk "$desktopPath/$newFileName.apk" | |
echo "✅ APK file successfully copied to desktop: $newFileName.apk" | |
fi | |
# Copy AAB | |
if $aabFound; then | |
cp build/app/outputs/bundle/*.aab "$desktopPath/$newFileName.aab" | |
echo "✅ AAB file successfully copied to desktop: $newFileName.aab" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment