-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_script.sh
More file actions
47 lines (34 loc) · 1.51 KB
/
build_script.sh
File metadata and controls
47 lines (34 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/zsh
# This script is used to build apk.
# get the app name from pubspec.yaml
appName=$(cat pubspec.yaml | grep name | awk '{print $2}' | tr -d '"')
# get the previous version
previousVersion=$(grep -oP '(?<=version: ).*' pubspec.yaml)
# get the current version
newVersion=$(echo $previousVersion | awk -F. '{$NF+=1}1' | sed 's/ /./g')
# get the previous build number
previousBuildNumber=$(echo $previousVersion | awk -Fdev '{print $NF}')
# get the new version
newVersion="$newVersion+dev$((previousBuildNumber + 1))"
# get the new build number
newBuildNumber=$((previousBuildNumber + 1))
# update the version in pubspec.yaml
sed -i "s/$previousVersion/$newVersion/g" pubspec.yaml
# git task
git add .
git commit -m "Update version to $newVersion"
git push
# build the apk
flutter build apk --split-per-abi --release --build-name=$newVersion --build-number=$newBuildNumber
# create a folder named $appName if it doesn't exist
if [ ! -d ~/Documents/$appName ]; then
mkdir ~/Documents/$appName
fi
# rename the apks and move them to the Documents/$appName folder
cp build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk ~/Documents/$appName/$appName-arm-$newVersion.apk
cp build/app/outputs/flutter-apk/app-arm64-v8a-release.apk ~/Documents/$appName/$appName-arm64-$newVersion.apk
echo "$appName has been built and saved to ~/Documents/$appName"
echo "Previous Version was $previousVersion"
echo "Previous Build Number $previousBuildNumber"
echo "New Version is $newVersion"
echo "New Build Number is $newBuildNumber"