iOS多应用自动打包

多应用自动打包

前言

网上很多文章都是陈词滥调,老黄历啦,在XCode多次更新后,那些脚本,那些命令已经不管用啦。

本文是基于XCode8.3版本的。

需求描述

要求做一个工具,可以批量打上百个应用,这些应用有不同的icon,启动图,bundleID,第三方账号,和其他一些业务相关的差异。

做起来~

重签名打包是有多种方法实现的。

我原来是用xcodebuild命令直接打出ipa包,然后重签名再导出的。

但执行xcrun -sdk iphoneos PackageApplication命令时发现,新版OS X已经没有PackageApplication工具了。

所以采用了以下方法:编译出xcarchive包,再使用xcodebuild导出ipa。

编译

xcodebuild -quiet -workspace xxx.xcworkspace -scheme xxx -configuration Release clean -sdk iphoneos -archivePath xxx.xcarchive archive

修改

修改bundleID等Info.plist中的内容:

简单的数据格式:

defaults write ${InfoPlistPath} key value

复杂的数据格式:

defaults write $InfoPlistPath "CFBundleURLTypes" -array-add "<dict>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>xxx</string>
			</array>
		</dict>"	

修改icon等资源文件

使用cp命令替换

重签名

一段题外话:由于某些错误,我打出了可以安装成功的adhoc包,但是检查证书才发现,是用的dev证书签名的,也是够神奇的了。

XCode8.3会在导出时自动根据bundleid重签名,但问题是不会自动修改包里的embedded.mobileprovision文件(也就是配置文件),会导致在使用Application Loader上传包时,报错说配置文件与签名证书不符。

我尝试过直接使用cp替换配置文件,但在导出时,它又给我换回去了。。。

所以采取了先重签名再导出的方法。

security cms -D -i "embedded.mobileprovision" > t_entitlements_full.plist
/usr/libexec/PlistBuddy -x -c 'Print:Entitlements' t_entitlements_full.plist > entitlements.plist
Entitlements=entitlements.plist

codesign -f -s "$tcertificationname" --entitlements $Entitlements ${tapppackagepath}

注意:--entitlements $Entitlements这个参数十分重要,对应的是一个plist文件,但不能通过手动编辑的方式生成这个文件,必须通过命令(好神奇吧)。

关于entitlements后续更新。

导出

defaults write ${exportoptionsplistpath} "teamID" "${tteamid}"
defaults write ${exportoptionsplistpath} "export_method" "${texportmethod}"
defaults write ${exportoptionsplistpath} "uploadSymbols" -bool true

xcodebuild  -exportArchive -exportOptionsPlist ${exportoptionsplistpath} -archivePath xxx.xcarchive -exportPath

-exportOptionsPlist参数是新出的,目前已知的参数有:

  • teamID
  • export_method:值为ad-hoc或者app-store,如果找不到该参数,就会使用dev证书签名。。。
  • uploadSymbols
posted @ 2017-04-16 21:19  小Garfield  阅读(2552)  评论(1编辑  收藏  举报