11---
22layout : post
3- title : iOS自动打包
4- subtitle : 利用 xcdeobulid 打包项目
3+ title : iOS 自动打包
4+ subtitle : 利用 xcdeobulid 打包项目、上传
55date : 2017-04-13
66author : BY
77header-img : img/post-bg-hacker.jpg
@@ -10,121 +10,130 @@ tags:
1010 - iOS
1111 - Xcode
1212 - shell
13+ - ruby
1314---
1415
1516
16- # 前言
17- > 利用xcode的命令行工具 ` xcdeobulid ` 进行项目的编译打包,生成ipa包
1817
18+ > 利用xcode的命令行工具 ` xcdeobulid ` 进行项目的编译打包,生成ipa包,并上传到fir
19+
20+
21+
22+ # 前言
1923现在网上的自动打包教程几乎都还是` xcodebuild + xcrun ` 的方式先生成` .app ` 包 再生成` .ipa ` 包,结果弄了一整天硬是没成功~
2024
2125后来发现` PackageApplication is deprecated ` ,悲剧。然后手动压缩的 ` .ipa ` 包因为签名问题无法装到手机上。
2226
2327后来用了` archive + -exportArchive ` 终于可以了~
2428
25- ## 查看项目详情
29+ ## 首先确保 ruby 的版本不是 2.4.0
30+ 在 ` ruby2.4.0 ` 下,由 archive 生成 ipa包 时会发生错误,需要切换 ` 2.4.0 ` 以下的版本(如 ` 2.3.3 ` )。
2631
27- xcodebuild 的使用可以用 ` man xcodebuild ` 查看。
32+ ## 查看项目详情
2833
29- 我只介绍关键的用法
34+ ** xcodebuild ** 的使用可以用 ` man xcodebuild ` 查看。
3035
3136查看项目详情
3237
38+ # cd 项目主目录
3339 xcodebuild -list
40+
41+ 输出项目的信息
42+
43+ Information about project "StackGameSceneKit":
44+ Targets:
45+ StackGameSceneKit
46+ StackGameSceneKitTests
47+
48+ Build Configurations:
49+ Debug
50+ Release
51+
52+ If no build configuration is specified and -scheme is not passed then "Release" is used.
53+
54+ Schemes:
55+ StackGameSceneKit
56+
57+ 要留意 ` Configurations ` ,` Schemes ` 这两个属性。
58+
59+ ## 打包流程
60+
61+ ### 生成 archive
62+
63+ 生成archive的命令是 ` xcodebuild archive `
64+
65+ xcodebuild archive -workspace ${project_name}.xcworkspace \
66+ -scheme ${scheme_name} \
67+ -configuration ${build_configuration} \
68+ -archivePath ${export_archive_path}
69+
70+ - 参数一:项目类型,,如果是混合项目 workspace 就用 ` -workspace ` ,如果是 project 就用 ` -project `
71+
72+ - ` -scheme ` :项目名,上面` xcodebuild -list ` 中的 ` Schemes `
73+
74+ - ` -configuration ` :编译类型,在` configuration ` 选择, ` Debug ` 或者 ` Release `
75+
76+ - ` -archivePath ` :生成 archive 包的路径,需要精确到 ` xx/xx.archive `
3477
35- ## 打包项目 archive -> ipa
3678首先需要创建一个` AdHocExportOptions.plist ` 文件
3779
38- 添加两个Key-Value
3980
40- - merhod : ad-hoc
41- - compileBitcode : NO
81+ ### 导出 ipa包
4282
43- 或者直接复制
83+ 导出ipa包这一步,在ruby2.4.0版本中会报错,所以请使用其他版本的ruby
4484
45- ```
46- <?xml version="1.0" encoding="UTF-8"?>
47- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
48- <plist version="1.0">
49- <dict>
50- <key>method</key>
51- <string>ad-hoc</string>
52- <key>compileBitcode</key>
53- <false/>
54- </dict>
55- ```
85+ 导出ipa包使用命令:` xcodebuild -exportArchive `
5686
57- 打包项目
58-
59- # 定义变量
60- workspaceName="xxx.xcworkspace"
61- scheme="xxx"
62- configuration="Release"
63- archivePath="./build/xxx.xcarchive"
64- exportOptionsPlist="AdHocExportOptions.plist"
65-
66- # 打包项目 -> .wcarchive
67- xcodebuild archive -workspace "$workspaceName" -scheme "$scheme" -archivePath "$archivePath"
68-
69- # 导出 .ipa
70- xcodebuild -exportArchive -archivePath "$archivePath" -exportPath "./build/" -exportOptionsPlist AdHocExportOptions.plist
87+ xcodebuild -exportArchive \
88+ -archivePath ${export_archive_path} \
89+ -exportPath ${export_ipa_path} \
90+ -exportOptionsPlist ${ExportOptionsPlistPath}
7191
72- 若转换ipa时** 失败** ,出现
7392
74- error: exportArchive: No applicable devices found.
75-
76- Error Domain=IDEDistributionErrorDomain Code=14 "No applicable devices found." UserInfo=0x7ff1a72ddd80 {NSLocalizedDescription=No applicable devices found.}
77-
78- ** EXPORT FAILED **
93+ - ` archivePath ` :上面生成 archive 的路径
94+ - ` -exportPath ` :导出 ipa包 的路径
95+ - ` exportOptionsPlist ` :导出 ipa包 类型,需要指定格式的` plist ` 文件,分别是` AppStroe ` 、` AdHoc ` 、` Enterprise ` ,如下图
7996
80- 则执行 [ 下面的脚本 ] ( http ://stackoverflow.com/questions/33041109/xcodebuild-no-applicable-devices-found-when-exporting-archive )
97+ ![ ] ( https ://ww3.sinaimg.cn/large/006tNc79gy1ff1bcz534ij30g609uq48.jpg )
8198
82- #!/bin/bash --login
83- [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
84- rvm use system
99+ 选择这三个类别需要分别创建三个 ` plist ` 文件:
100+
101+ - ` AdHocExportOptionsPlist.plist `
85102
86- 然后继续 ` xcodebuild -exportArchive `
103+ 
104+ - ` AppStoreExportOptionsPlist.plist `
105+
106+ 
107+ - ` EnterpriseExportOptionsPlist.plist `
87108
88- ## 上传到 [ Fir ] ( https://fir.im )
109+ 
89110
90- 因为上面的操作切换了ruby
91111
92- 所以 ** 将ruby切换回来 ** 或 ** 新建一个终端窗口 ** ,
112+ ### 上传到 Fir
93113
94- rvm use default
114+ 将项目上传到 [ Fir ] ( https://fir.im )
95115
96116下载 [ fir 命令行工具] ( https://github.com/FIRHQ/fir-cli/blob/master/doc/install.md )
97117
98118 gem install fir-cli
99119
100120获取 fir 的 API Token(右上角)
101121
102- 然后上传
122+ ![ ] ( https://ww3.sinaimg.cn/large/006tNc79gy1ff28ccsqhyj304t07bwei.jpg )
103123
104- # 第一次上传需要 ApiToken
105- firApiToken="xxx"
106- ipaPath="xxx.ipa"
107- fir publish "$ipaPath" -T "$firApiToken"
124+ 上传
125+
126+ fir publish "ipa_Path" -T "firApiToken"
108127
109- # 再次上传不需要
110- fir publish "$ipaPath.ipa"
111128
112129
113- # 问题
130+ # 自动打包脚本
114131
115- 我将这些脚本写入 ` .sh ` 文件执行时,执行到这句话时
132+ ### 再次提醒,请不要使用 ruby 2.4.0 运行该脚本!
116133
117- rvm use system
118-
119- 会出现如下错误
134+ 脚本我fork了 [ jkpang] ( https://github.com/jkpang/PPAutoPackageScript ) 的脚本进行修改,添加了自动上传到fir的功能。
120135
121- RVM is not a function, selecting rubies with 'rvm use ...' will not work.
122-
123- You need to change your terminal emulator preferences to allow login shell.
124- Sometimes it is required to use `/bin/bash --login` as the command.
125- Please visit https://rvm.io/integration/gnome-terminal/ for an example.
136+ 代码地址:< https://github.com/qiubaiying/iOSAutoArchiveScript >
126137
127- Google很久无果,知道的朋友望帮忙解决,十分感谢~
128138
129139> 本文首次发布于 [ BY Blog] ( http://qiubaiying.github.io ) , 作者 [ @柏荧(BY)] ( http://github.com/qiubaiying ) ,转载请保留原文链接.
130-
0 commit comments