Skip to content

Commit f82e398

Browse files
committed
add post
fix podst
1 parent 1966ea2 commit f82e398

File tree

2 files changed

+142
-71
lines changed

2 files changed

+142
-71
lines changed

_posts/2017-04-13-iOS自动打包.md

Lines changed: 80 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: post
3-
title: iOS自动打包
4-
subtitle: 利用 xcdeobulid 打包项目
3+
title: iOS 自动打包
4+
subtitle: 利用 xcdeobulid 打包项目、上传
55
date: 2017-04-13
66
author: BY
77
header-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+
![](https://ww3.sinaimg.cn/large/006tNc79gy1ff1bhmwvxfj30ax01pdfu.jpg)
104+
- `AppStoreExportOptionsPlist.plist`
105+
106+
![](https://ww3.sinaimg.cn/large/006tNc79gy1ff1bijdlsgj30bh01st8q.jpg)
107+
- `EnterpriseExportOptionsPlist.plist`
87108

88-
## 上传到 [Fir](https://fir.im)
109+
![](https://ww4.sinaimg.cn/large/006tNc79gy1ff1bishpk8j30be01sglm.jpg)
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-
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
layout: post
3+
title: RVM 使用指南
4+
subtitle: RVM 常用的命令整理
5+
date: 2017-04-13
6+
author: BY
7+
header-img: img/post-bg-hacker.jpg
8+
catalog: true
9+
tags:
10+
- iOS
11+
- RVM
12+
- shell
13+
- ruby
14+
---
15+
16+
> RVM 常用的命令整理
17+
18+
RVM 是一个命令行工具,可以提供一个便捷的多版本 Ruby 环境的管理和切换。<https://rvm.io/>
19+
20+
我相信做为iOS开发者,对ruby的使用都是从安装ocoapods吧
21+
22+
>**注意**:这里所有的命令都是再用户权限下操作的,任何命令最好都不要用 sudo.
23+
24+
## RVM 安装
25+
26+
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
27+
$ \curl -sSL https://get.rvm.io | bash -s stable
28+
$ source ~/.bashrc
29+
$ source ~/.bash_profile
30+
31+
修改 RVM 的 Ruby 安装源到 Ruby China 的 Ruby 镜像服务器,这样能提高安装速度
32+
33+
$ echo "ruby_url=https://cache.ruby-china.org/pub/ruby" > ~/.rvm/user/db
34+
35+
## Ruby 的安装与切换
36+
37+
列出已知的 Ruby 版本
38+
39+
rvm list known
40+
41+
安装一个 Ruby 版本
42+
43+
rvm install 2.2.0 --disable-binary
44+
45+
切换 Ruby 版本
46+
47+
rvm use 2.2.0
48+
49+
如果想设置为默认版本,这样一来以后新打开的控制台默认的 Ruby 就是这个版本
50+
51+
rvm use 2.2.0 --default
52+
53+
查询已经安装的ruby
54+
55+
rvm list
56+
57+
卸载一个已安装版本
58+
59+
rvm remove 1.8.7
60+
61+
62+
>参考:<https://ruby-china.org/wiki/rvm-guide>

0 commit comments

Comments
 (0)