flutter_build.sh
3.31 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
build_ios=false
build_android=false
build_release=false
build_debug=false
updatePodfile(){
if [ "$build_ios" == true ] && [ -d ".ios" ]; then
# 修改Podfile platform版本
sed -i '' "1s/.*/platform :ios, \"17.0\"/" .ios/Podfile
modifyPodfileConfigPermissionHandler
fi
}
# 修改podfile文件: 解决permission_handler在iOS方授权的问题
modifyPodfileConfigPermissionHandler() {
# 定义文件路径
PODFILE=".ios/Podfile"
PERMISSION_HANDLER_CONFIG="permission_handler_config"
# 检查是否已经包含 `target.name == "permission_handler_apple"`
if grep -q 'target.name == "permission_handler_apple"' "$PODFILE"; then
echo "Podfile already contains 'target.name == \"permission_handler_apple\"'. No insertion needed."
return 0
fi
# 查找插入位置
LINE_NUMBER=$(grep -n 'installer.pods_project.targets.each do |target|' "$PODFILE" | cut -d: -f1)
# 如果找到匹配行,则插入内容
if [ ! -z "$LINE_NUMBER" ]; then
# 将匹配行号加1,作为插入行号
INSERT_LINE=$((LINE_NUMBER + 1))
# 在指定行之后插入内容
sed -i '' "${INSERT_LINE}r ${PERMISSION_HANDLER_CONFIG}" "$PODFILE"
else
echo "未找到匹配的行。"
fi
}
checkSDKDir() {
if [ "$build_ios" == true ] && [ -d "./SDK/iOS_SDK" ]; then
rm -rf ./SDK/iOS_SDK/*
else
mkdir -p ./SDK/iOS_SDK
fi
if [ "$build_android" == true ] && [ -d "./SDK/Android_SDK" ]; then
rm -rf ./SDK/Android_SDK/*
else
mkdir -p ./SDK/Android_SDK
fi
}
buildIOSSDk() {
echo "\033[33mBegin Build iOS SDK\033[0m"
if [[ "$build_release" == true ]]; then
flutter build ios-framework --no-debug --no-profile --xcframework --no-universal --output=./
mv ./Release/* ./SDK/iOS_SDK
rm -rf ./Release
else
flutter build ios-framework --no-release --no-profile --xcframework --no-universal --output=./
mv ./Debug/* ./SDK/iOS_SDK
rm -rf ./Debug
fi
echo "\033[33miOS SDK Done\033[0m"
}
buildAndroidSDK() {
echo "\033[33mBegin Build Android SDK\033[0m"
if [[ "$build_release" == true ]]; then
echo "\033[33mRelease Version\033[0m"
flutter build aar --no-profile --no-debug
elif [[ "$build_debug" == true ]]; then
echo "\033[33mDebug Version\033[0m"
flutter build aar --no-profile --no-release
else
echo "\033[33mRelease&Debug Version\033[0m"
flutter build aar --no-profile
fi
mv ./build/host/outputs/repo/* ./SDK/Android_SDK
rm -rf ./build
echo "\033[33mAndroid SDK Done\033[0m"
}
while getopts ":iard" optname; do
case "$optname" in
"i")
build_ios=true
;;
"a")
build_android=true
;;
"r")
build_release=true
;;
"d")
build_debug=true
;;
":")
echo "\033[31mNo argument value for option $OPTARG\033[0m"
;;
"?")
echo "\033[31mUnknown option $OPTARG\033[0m"
;;
*)
echo "\033[31mUnknown error while processing options\033[0m"
;;
esac
#echo "option index is $OPTIND"
done
all_platform=false
if [ "$build_ios" == false ] && [ "$build_android" == false ]; then
all_platform=true
fi
echo """\033[36m
Build iOS / Android: ($build_ios / $build_android)
Build All Platform: $all_platform
Build Release: $build_release\033[0m
"""
checkSDKDir
if [[ "$build_ios" == true ]]; then
updatePodfile
buildIOSSDk
elif [[ "$build_android" == true ]]; then
buildAndroidSDK
else
updatePodfile
buildIOSSDk
buildAndroidSDK
fi