0%

Flutter+Jenkins持续发布IPA和APK包

前端时间公司在AppStore上架了Flutter的App,起步阶段是通过Xcode人手打包IPA给测试同学进行测试,随着迭代速度加快,这种方式非常不便,遂接入到现有的Jenkins平台进行持续发布,以此文记录一些关键点。

环境

Xcode11 + Flutter 1.9.1+hotfix.4

命令行

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
# Build iOS
# Enter ios folder
cd ios

# Unlock keychain
keychain=~/Library/Keychains/login.keychain-db
security unlock-keychain -p "系统密码" ${keychain} &>/dev/null
if [ $? -ne 0 ];then
echo "Cannot open keychain ${keychain}"
exit 1
fi

# Create exportOptionsPlist
cat > ExportOptionsPlist.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>enterprise</string>
<key>provisioningProfiles</key>
<dict>
<key>com.xxx</key>
<string>xxxx</string>
</dict>
</dict>
</plist>
EOF

# Build IPA
Derived_Path=./deriveddata
Workspace_Name="Runner"
Project_Name="Runner"
Configuration="Release"
ExportOptionsPlist=./ExportOptionsPlist.plist
ExportOptionsPlist=${ExportOptionsPlist}

rm -rf $Derived_Path

xcodebuild -derivedDataPath $Derived_Path -workspace $Workspace_Name.xcworkspace -scheme $Project_Name -configuration $Configuration -archivePath build/$Project_Name-enterprise.xcarchive archive build
xcodebuild -exportArchive -archivePath build/$Project_Name-enterprise.xcarchive -exportOptionsPlist ${ExportOptionsPlist} -exportPath build/output

# Build Android
cd ..
flutter build apk --release

解释

  1. 编译过程中会提示错误:Command CodeSign failed with a nonzero exit code,通过Unlock keychain解决;
  2. 因为导出的是企业包,需要提供相应的exportOptionsPlist文件,不想提交到代码管理,所以使用脚本的方式生成此文件,填充method和provisioningProfiles两个字段即可;
  3. 打包IPA没直接使用flutter build ios –release是因为这个命令行只能生成.app,这里需要生成ipa包并提交到ota服务器,所以使用xcodebuild进行构建打包;
  4. 打包APK直接使用命令行:flutter build apk –release,没法指定生成目录,默认生成路径是:build/app/outputs/apk/app.apk;
  5. 完成后通过curl提交到公司内部的OTA和存储服务器。