作为开发人员,每次给测试打包是一件很痛苦的事情,所以本着懒惰的思想,我就在想,在我电脑证书都配备齐全的前提下,能不能用终端实现一键打包,并自动上传内测网站(如:蒲公英,fir等),并自动发邮件通知相关人员(这个功能我暂时未实现,希望知道的朋友能告诉我下怎么实现,在此谢过了!).通过网上的搜索,发现还真有这样的方法,但是所谓是,八仙过海各显神通,各种方法都有,有shell脚本的,有配置enkins,本人找了个最简单的,就是终端的,在此将过程记录在此,以便自己日后学习!
安装fir-cli
$ gem install fir-cli
出现 Gem::RemoteFetcher::FetchErro:
错误,更换Ruby环境。
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://gems.ruby-china.org/
$ gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.org
# 请确保只有 gems.ruby-china.org, 如果有其他的源, 请 remove 掉
gem update --system
gem install fir-cli
安装成功出现如下界面
bogon:~ ×××××××××$ gem install fir-cli
______________ ________ ____
/ ____/ _/ __ \ / ____/ / / _/
/ /_ / // /_/ /_____/ / / / / /
/ __/ _/ // _, _/_____/ /___/ /____/ /
/_/ /___/_/ |_| \____/_____/___/
## 更新记录
### fir-cli 1.5.0
- 修正 build 后直接 -p 发布的权限错误
- 增加上传时候设置密码及公开访问权限
- 增加 build_ipa 中的 destination 参数
- 详细更新记录, 请查看: https://github.com/FIRHQ/fir-cli/blob/master/CHANGELOG
- [fir-cli](https://github.com/FIRHQ/fir-cli) 已经开源
- 欢迎 fork, issue 和 pull request
Successfully installed fir-cli-1.5.0
Parsing documentation for fir-cli-1.5.0
Done installing documentation for fir-cli after 0 seconds
1 gem installed
fir help 相关指令帮助
$ fir info --help
查看 ipa 相关信息
$ fir help
Commands:
fir build_apk BUILD_DIR # Build Android app (alias: `ba`).
fir build_ipa BUILD_DIR [options] [settings] # Build iOS app (alias: `bi`).
fir help # Describe available commands or one specific command (aliases: `h`).
fir info APP_FILE_PATH # Show iOS/Android app info, support ipa/apk file (aliases: `i`).
fir login # Login fir.im (aliases: `l`).
fir mapping MAPPING_FILE_PATH # Upload app mapping file to BugHD.com (aliases: `m`).
fir me # Show current user info if user is logined.
fir publish APP_FILE_PATH # Publish iOS/Android app to fir.im, support ipa/apk file (aliases: `...
fir upgrade # Upgrade fir-cli and quit (aliases: `u`).
fir version # Show fir-cli version number and quit (aliases: `v`).
Options:
-T, [--token=TOKEN] # User's API Token at fir.im
-L, [--logfile=LOGFILE] # Path to writable logfile
-V, [--verbose], [--no-verbose] # Show verbose
# Default: true
-q, [--quiet], [--no-quiet] # Silence commands
-h, [--help], [--no-help] # Show this help message and quit
fir help 相关指令帮助
Start with a line containing 3 or more backticks, and ends with the first line with the same number of backticks:
Fenced code blocks are like Stardard Markdown’s regular code
blocks, except that they’re not indented and instead rely on
a start and end fence lines to delimit the code block.
至此,fir的基本能用到的命令就介绍到这里,fir详细的具体使用请参考https://github.com/FIRHQ/fir-cli/blob/master/doc/login.md
最后在终端使用以下命令行打包
1.先打出IPA的包
bogon:~ ×××××××××$ fir build_ipa /Users/wuxianlvzhou/Desktop/ios_app/Panda/FatherKnows.xcworkspace -o /Users/wuxianlvzhou/Desktop/CMD-IPA -w -C Release -S FatherKnows
I, [2016-12-22T14:54:55.727448 #23628] INFO -- : Building......
I, [2016-12-22T14:54:55.727503 #23628] INFO -- : ✈ -------------------------------------------- ✈
I, [2016-12-22T14:57:57.537316 #23628] INFO -- : 2016-12-22 14:54:56.358 xcodeb
......
adding: Payload/FatherKnows.app/FatherKnows .... (in=43090752) (out=14588655) (deflated 66%)
total bytes=63723391, compressed=29841064 -> 53% savings
]
Results at '/var/folders/25/frh3dbts1mx9121vthcxqfrm0000gn/T/d20161222-29464-141md40/1482394115.ipa'
I, [2016-12-22T16:08:42.108844 #29464] INFO -- : Build Success
I, [2016-12-22T16:08:42.108938 #29464] INFO -- :
fir build_ipa 【项目路径的.xcworkspace】 -o 【打出来的IPA包的路径】 -w -C【编译环境】 -S【项目名称】 -p
2.上传fir内测网
bogon:~ ×××××××××$ fir publish /Users/wuxianlvzhou/Desktop/CMD-IPA/FatherKnows-1.2.5-build-1.ipa
I, [2016-12-22T16:11:27.153723 #32104] INFO -- : Publishing app via allisonwangjj<×××××××××@126.com>.......
I, [2016-12-22T16:11:27.153851 #32104] INFO -- : ✈ -------------------------------------------- ✈
I, [2016-12-22T16:11:28.639772 #32104] INFO -- : Fetching com.panda.usecar@fir.im uploading info......
I, [2016-12-22T16:11:28.639845 #32104] INFO -- : Uploading app: 盼达用车-1.2.5(Build 1)
I, [2016-12-22T16:11:28.910179 #32104] INFO -- : Uploading app icon......
I, [2016-12-22T16:11:28.910306 #32104] INFO -- : Converting app's icon......
I, [2016-12-22T16:11:29.694721 #32104] INFO -- : Uploading app binary......
I, [2016-12-22T16:12:05.190147 #32104] INFO -- : Updating devices info......
I, [2016-12-22T16:12:05.763234 #32104] INFO -- : Fetch app info from fir.im
I, [2016-12-22T16:12:05.927531 #32104] INFO -- : ✈ -------------------------------------------- ✈
I, [2016-12-22T16:12:05.927618 #32104] INFO -- : Published succeed: http://fir.im/g3v8
I, [2016-12-22T16:12:05.927680 #32104] INFO -- :
bogon:~ ×××××××××$
当终端出现Published succeed的时候 到fir官网,https://fir.im查看应用的时间已经改变了
上面的两个命令步骤也可以用一条命令来实现
打包IPA并上传fir的命令:
fir build_ipa /Users/wuxianlvzhou/Desktop/ios_app/Panda/FatherKnows.xcworkspace -o /Users/wuxianlvzhou/Desktop/CMD-IPA -w -C Release -S 盼达用车 -p
fir build_ipa 【项目路径的.xcworkspace】 -o 【打出来的IPA包的路径】 -w -C【编译环境】 -S【项目名称】 -p
至此,整个iOS打包基本上已经完成了,但是,通过不断的修改bug,不断的打包上传fir我们可以发现builde并不会发生改变,如下图所示:
Build.png所以我们可以配置一个Xcode打包iOS应用时自动增加编译号的方法,具体做法如下
Xcode打包iOS应用时自动增加编译号
每次上传到iTunes Connect的iOS应用包,如果是新版本,则版本号(version)必须也要比之前的版本号大。如果版本号一样,则编译号(build number)是必须比之前的编译号大。如上一个版本是1.2.4,其中1.2是版本号,4是编译号,则此次上传的编译号必须大于4.但是每次都去手动修改编译号是很麻烦的,有时候你都花了2个小时打包好应用后,发现编译号居然没改,这就坑爹了。于是我就想能不能每次打包时能够自动增加编译号。我经过两个晚上的尝试,找到了办法来实现这个功能。
选择“Build Phases”选项卡
点击红框标注的“+”按钮
2.png在弹出的菜单中选择“New Run Script Phase..."
3.png
修改名称,单击红框标注的“Run Script",此处是为了增加编译号,所以名称我就改成了Build Number
4.png
在红框标注的输入框中输入:
5.png
echo $CONFIGURATION
if [ "Release" == "${CONFIGURATION}" ]
then
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
echo "build number increase"
fi
之后,每次打包,红框标注的编译号都会增加1
6.png
这里我只是将网上的一些资料收集规整,并加以总结.
网友评论
The xcodeproj file is missing, check the BUILD_DIR 这是怎么回事 ???
Release
Print: Entry, "CFBundleVersion", Does Not Exist
/Users/neghao/BaiKe/BLive/build/BLive/Release-iphoneos/BLive.build/Script-0A2FC9B71E4C309000F2F0C3.sh: line 6: File Doesn't Exist, Will Create: /Users/neghao/BaiKe/BLive//Users/neghao/BLive/BLive/BLive/Info.plist + 1: syntax error: invalid arithmetic operator (error token is "'t Exist, Will Create: /Users/neghao/BaiKe/BLive//Users/neghao/BaiKe/BLive/BLive/Info.plist + 1")
Command /bin/sh failed with exit code 1