Skip to content

Commit e938083

Browse files
committed
new post
1 parent b1f6168 commit e938083

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

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

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
layout: post
3+
title: iOS自动打包
4+
subtitle: 利用 xcdeobulid 打包项目
5+
date: 2017-04-13
6+
author: BY
7+
header-img: img/post-bg-universe.jpg
8+
catalog: true
9+
tags:
10+
- iOS
11+
- Xcode
12+
- shell
13+
---
14+
15+
# iOS自动打包
16+
17+
> 利用xcode的命令行工具 `xcdeobulid` 进行项目的编译打包,生成ipa包
18+
19+
# 前言
20+
现在网上的自动打包教程几乎都还是`xcodebuild + xcrun`的方式先生成`.app`包 再生成`.ipa`包,结果弄了一整天硬是没成功~
21+
22+
后来发现`PackageApplication is deprecated`,悲剧。然后手动压缩的 `.ipa`包因为签名问题无法装到手机上。
23+
24+
后来用了`archive + -exportArchive`终于可以了~
25+
26+
## 查看项目详情
27+
28+
xcodebuild 的使用可以用 `man xcodebuild`查看。
29+
30+
我只介绍关键的用法
31+
32+
查看项目详情
33+
34+
xcodebuild -list
35+
36+
## 打包项目 archive -> ipa
37+
首先需要创建一个`AdHocExportOptions.plist`文件
38+
39+
添加两个Key-Value
40+
41+
- merhod : ad-hoc
42+
- compileBitcode : NO
43+
44+
或者直接复制
45+
46+
```
47+
<?xml version="1.0" encoding="UTF-8"?>
48+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
49+
<plist version="1.0">
50+
<dict>
51+
<key>method</key>
52+
<string>ad-hoc</string>
53+
<key>compileBitcode</key>
54+
<false/>
55+
</dict>
56+
```
57+
58+
打包项目
59+
60+
# 定义变量
61+
workspaceName="xxx.xcworkspace"
62+
scheme="xxx"
63+
configuration="Release"
64+
archivePath="./build/xxx.xcarchive"
65+
exportOptionsPlist="AdHocExportOptions.plist"
66+
67+
# 打包项目 -> .wcarchive
68+
xcodebuild archive -workspace "$workspaceName" -scheme "$scheme" -archivePath "$archivePath"
69+
70+
# 导出 .ipa
71+
xcodebuild -exportArchive -archivePath "$archivePath" -exportPath "./build/" -exportOptionsPlist AdHocExportOptions.plist
72+
73+
若转换ipa时**失败**,出现
74+
75+
error: exportArchive: No applicable devices found.
76+
77+
Error Domain=IDEDistributionErrorDomain Code=14 "No applicable devices found." UserInfo=0x7ff1a72ddd80 {NSLocalizedDescription=No applicable devices found.}
78+
79+
** EXPORT FAILED **
80+
81+
则执行[下面的脚本](http://stackoverflow.com/questions/33041109/xcodebuild-no-applicable-devices-found-when-exporting-archive)
82+
83+
#!/bin/bash --login
84+
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
85+
rvm use system
86+
87+
然后继续 `xcodebuild -exportArchive`
88+
89+
## 上传到 [Fir](https://fir.im)
90+
91+
因为上面修复ruby的原因,可能出现下载问题
92+
93+
所以 **新建一个终端窗口**
94+
95+
下载 [fir 命令行工具](https://github.com/FIRHQ/fir-cli/blob/master/doc/install.md)
96+
97+
gem install fir-cli
98+
99+
获取 fir 的 API Token(右上角)
100+
101+
然后上传
102+
103+
# 第一次上传需要 ApiToken
104+
firApiToken="xxx"
105+
ipaPath="xxx.ipa"
106+
fir publish "$ipaPath" -T "$firApiToken"
107+
108+
# 再次上传不需要
109+
fir publish "$ipaPath.ipa"
110+
111+

0 commit comments

Comments
 (0)