shell自动打包IPA

自动打包ipa,测试发现时间和用xcode打包差不多,但可以减少鼠标点击操作。

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
#!/bin/bash

#----------使用说明---
#将EnterpriseExportOptionsPlist放在.xcodeproj同级目录
#运行脚本,直接拖放项目目录(.xcodeproj上级文件夹)
#mac 下终端访问文件出现“Permission Denied”解决方案:chmod a+x ./文件名
#----------使用说明 END---

#配置信息--Start---------
version_string="3.5.0" #版本号-空值不设置
build_number="3.5.1286" #版本号-空值不设置

##企业(enterprise)证书名&描述文件
ENTERPRISECODE_SIGN_IDENTITY="iPhone Distribution: xxx Service Co., Ltd."
EnterpriseBundleID="com.xxx.inhouse"
ENTERPRISEROVISIONING_PROFILE_NAME="73c2dfe3-ebc4-4801-bbd6-e4ba25f14fe9"


echo "请拖入项目文件目录(.xcodeproj文件的上层目录)"
# 读取用户输入并存到变量里
read user_input
Project_Path=$user_input

#EnterpriseExportOptionsPlist文件路径
EnterpriseExportOptionsPlist=$Project_Path/EnterpriseExportOptionsPlist.plist



echo "$EnterpriseExportOptionsPlist" 
echo "$Project_Path" 
cd $Project_Path

#查找项目名称
Project_Name=`find . -name *.xcodeproj | awk -F "[/.]" '{print $(NF-1)}'`

###############获取版本号,bundleID
info_plist=$Project_Path/$Project_Name/Info.plist
echo "~~~0~$Project_Name~~~~~"
ipa_outPath=~/Desktop/$Project_Name #保存ipa文件到桌面

echo "~~~~~开始编译~~~~~"

#修改plist 版本号,修改build号函数--放在调用前
PlistBuddy_setting(){
echo "~~~~~修改plist版本号~~~~~"
bundleVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $info_plist`
bundleIdentifier=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $info_plist`
bundleBuildVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $info_plist`
echo "~~~工程名~~~~~$Project_Name~~Bundle ID~~~$bundleIdentifier~~版本号~~~~~$bundleBuildVersion"

if [ ! -n $version_string ]; then
echo "IS NULL"
else
# 修改版本号
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version_string" "${info_plist}"
fi

if [ ! -n $version_string ]; then
echo "IS NULL"
else
# 修改build号
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $build_number" ${info_plist}
fi
}


xcodebuild_Archive(){
xcodebuild -project $Project_Name.xcodeproj -scheme $Project_Name -configuration Release -archivePath $Project_Name-enterprise.xcarchive clean archive build CODE_SIGN_IDENTITY="${ENTERPRISECODE_SIGN_IDENTITY}" PROVISIONING_PROFILE="${ENTERPRISEROVISIONING_PROFILE_NAME}" PRODUCT_BUNDLE_IDENTIFIER="${EnterpriseBundleID}"
}

xcodebuild_ExportArchive(){
xcodebuild -exportArchive -archivePath $Project_Name-enterprise.xcarchive -exportOptionsPlist $EnterpriseExportOptionsPlist -exportPath $ipa_outPath
}

#清理工程
xcodebuild -project ${Project_Path}/${Project_Name}.xcodeproj clean

#利用PlistBuddy修改plist信息
PlistBuddy_setting;

#企业打包脚本
xcodebuild_Archive; #第一步--archive-.xcarchive
xcodebuild_ExportArchive; #第二步--exportArchive-ipa

if [ -d "$ipa_outPath" ]; then
echo "导出成功✅!! $ipa_outPath" 
open $ipa_outPath
fi
文章作者: kyren
文章链接: http://huluo666.github.io/2017/03/19/shell自动打包IPA/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Kyren's Blog