使用Flutter Distributor打包Flutter应用
2022-06-28 本文已影响0人
卢叁
Flutter Distributor是使用Dart写的CI工具,可用于打包和发布Flutter应用。官方文档
安装
dart pub global activate flutter_distributor
用法
将 distribute_options.yaml
添加到项目根目录,并设定ipa、apk文件输出路径:
output: dist/
配置发布项
build_args
是 flutter build
命令所支持的参数,可根据项目进行修改。
env:
PGYER_API_KEY: 'your api key'
output: dist/
releases:
- name: dev
jobs:
# 构建 apk 包并将其发布到 pgyer
- name: release-dev-android
package:
platform: android
target: apk
build_args:
target-platform: android-arm,android-arm64
dart-define:
APP_ENV: dev
publish_to: pgyer
# 构建 ipa 包并将其发布到 pgyer
- name: release-dev-ios
package:
platform: ios
target: ipa
build_args:
export-options-plist: ios/ExportOptions.plist
dart-define:
APP_ENV: dev
publish_to: pgyer
发布应用
# 安卓包
flutter_distributor release --name dev --jobs release-dev-android
# iOS包
flutter_distributor release --name dev --jobs release-dev-ios
# iOS及安卓包
flutter_distributor release --name dev
目前Flutter Distributor
还没支持打完包后钉钉通知相应测试人员,所以可以自己添加脚本使用curl
来做,shell
脚本如下:
#!/bin/bash
check_results=`flutter_distributor --version`
if [[ $check_results =~ "0.1.8" ]]
then
echo "flutter_distributor version is 0.1.8, it seems not need to install flutter_distributor again."
else
echo "It is going to install flutter_distributor 0.1.8 version"
dart pub global activate flutter_distributor 0.1.8
fi
echo "请选择打包方式 ? [ 1:安卓 2:iOS 3:iOS加安卓 4:安卓国内v7及v8]"
read number
while ([[ $number != 1 ]] && [[ $number != 2 ]] && [[ $number != 3 ]] && [[ $number != 4 ]])
do
echo "请选择打包方式 ? [ 1:安卓 2:iOS 3:iOS加安卓 4:安卓国内v7及v8]"
read number
done
url="https://oapi.dingtalk.com/robot/send?access_token=xxx"
readonly url;
echo $url
downUrlForiOS="https://www.pgyer.com/xxx"
readonly downUrlForiOS
echo $downUrlForiOS
downUrlForAndroid="https://www.pgyer.com/xxx"
readonly downUrlForAndroid
echo $downUrlForAndroid
#at
phones='"xxx","xxx"'
readonly phones;
echo $phones
#测试描述
desc='请测试'
echo $number
if [ $number -eq 1 ];then
echo "安卓开始打包"
# 安卓包
flutter_distributor release --name dev --jobs release-dev-android
# 上传蒲公英
curl -H 'Content-Type: application/json' -X POST -d '{
"at": {
"atMobiles":['"$phones"'],
"isAtAll": false
},
"text": {
"content":"安卓新包:'$downUrlForAndroid','$desc'"
},
"msgtype":"text"
}' $url
echo -e "\n upload android success \n"
elif [ $number -eq 2 ]; then
echo "iOS开始打包"
# iOS包
flutter_distributor release --name dev --jobs release-dev-ios
# 上传蒲公英
curl -H 'Content-Type: application/json' -X POST -d '{
"at": {
"atMobiles":['"$phones"'],
"isAtAll": false
},
"text": {
"content":"iOS新包:'$downUrlForiOS','$desc'"
},
"msgtype":"text"
}' $url
echo -e "\n upload iOS success \n"
elif [ $number -eq 3 ]; then
echo "安卓及iOS开始打包"
# iOS&安卓包
flutter_distributor release --name dev
# 上传蒲公英
curl -H 'Content-Type: application/json' -X POST -d '{
"at": {
"atMobiles":['"$phones"'],
"isAtAll": false
},
"text": {
"content":"安卓新包:'$downUrlForAndroid',\n iOS新包: '$downUrlForiOS','$desc'"
},
"msgtype":"text"
}' $url
echo -e "\n upload iOS、android success \n"
fi
exit