iOS 自动化打包--(手动运行xcodebuild命令)

无论是Xcode的Archive打包和导出还是运行脚本xxx.sh文件,基本都是基于xcodebuild工具,只是在Xcode 8.3之前通常使用的是xcodebuild archive 和xcodebuild xcrun ,在之后的Xcode8.3以后的版本 9.0,10.0,都是基本基于xcodebuild archive 和xcodebuild -exportArchive 来实现自动化打包。

首先,来看一下xcodebuild的常用命令,可以通过 man xcodebuild来查看,

如果要查看xcodebuild的使用实例,可以通过使用命令 xcodebuild --help来查看。

如果要查看当前工程的常用配置:可以使用 xcodebuild -list,可以看到工程的Target ,scheme,configuration配置参数。

 

在打包的过程中 实际使用到的命令 一共也就三个 xcodebuild clean 表示清理工程。

  • xcodebuild clean

1.如果不是workspace容器承载的项目,

xcodebuild clean -project ${ProjectName}.xcodeproj -target ${Target} -scheme ${scheme} -configuration ${Debug或者Release}  -quiet -UseNewBuildSystem=NO
  • ${ProjectName} 工程的项目名字
  •  ${Target} 当前要运行的Target 
  • ${scheme} 当前要编译运行的scheme
  • ${Debug或者Release} 当前是要以Debug运行还是以Release运行
  • -quiet 忽略警告提示打印
  • -UseNewBuildSystem=NO 是否使用新的build系统 

2.如果是工程是workspace承载的,可以使用xcodebuild命令

xcodebuild clean -workspace ${workspace名字}.xcworkspace -scheme ${scheme名字} -configuration${Debug,Release}  -UseNewBuildSystem=NO
  • ${workspace} 工程中,.xcworkspace的文件名字 
  • ${scheme} 当前要编译运行的scheme
  • configuration ${Debug或者Release} 当前是要以Debug运行还是以Release运行
  • -quiet 忽略警告提示打印
  • -UseNewBuildSystem=NO 是否使用新的build系统 

这是属于日常的工程清理,或者打包之前的工程清理。

  • xcodebuild archive 编程打包文件
xcodebuild archive -workspace  ${workspace名字}.xcworkspace -scheme ${scheme} -configuration ${Debug,Release} -archive_path=${archive_path}

1.如果不配置证书 和运行文件

  • ${workspace} 工程中,.xcworkspace的文件名字 
  • ${scheme} 当前要编译运行的scheme
  • configuration ${Debug或者Release} 当前是要以Debug运行还是以Release运行
  •  -archive_path 导出文件的路径 

示例:

xcodebuild archive -workspace  GomeShop.xcworkspace -scheme  GomeShop -configuration Release -archive_path=/Users/xiaofeiniao/Desktop

2.配置证书文件的

xcodebuild archive -workspace ${workspace}.xcworkspace -scheme ${scheme} -configuration ${Debug,Release} -archivePath ${archivePath} CODE_SIGN_IDENTITY = ${CODE_SIGN_IDENTITY} PROVISIONING_PROFILE=${PROVISIONING_PROFILE}
  • ${workspace} 工程中,.xcworkspace的文件名字 
  • ${scheme} 当前要编译运行的scheme
  • configuration ${Debug或者Release} 当前是要以Debug运行还是以Release运行
  •  -archive_path 导出文件的路径 
  • CODE_SIGN_IDENTITY 证书文件名
  • PROVISIONING_PROFILE 运行文件UUID

CODE_SIGN_IDENTITY获取方法:

打开你的钥匙串访问->选中其中一个证书->右键->显示简介,把标题复制出来就可以了。

格式:

iPhone Distribution: xxxx e-commerce Co., Ltd. (KYACQ4K486)

获取Provisioning文件UUID

在xcode8.0以上,Provisioning文件的位置是:

/Users/用户名/Library/MobileDevice/Provisioning Profiles

在终端上面进入的文件夹。使用/usr/bin/security可以把Provisioning文件解密

/usr/bin/security cms -D -i xxx.mobileprovision

打开之后,就是一个plist格式的文件。

示例:

xcodebuild archive -workspace GomeShop.xcworkspace -scheme GomeShop -configuration Release -archivePath "~/Desktop/GomeShop.xcarchive" "CODE_SIGN_IDENTITY ="iPhone Distribution: Xin rui mei e-commerce Co., Ltd. (KYACQ4K486)" PROVISIONING_PROFILE="c7ec43dc-a544-4f84-b787-a86ff8770a65"
  • xcodebuild -exportArchive 导出IPA包
xcodebuild -exportArchive -archivePath archive文件的地址.xcarchive 
                          -exportPath 导出的文件夹地址 
                          -exportOptionsPlist exprotOptionsPlist.plist 
                          CODE_SIGN_IDENTITY=证书 
                          PROVISIONING_PROFILE=描述文件UUID

示例:

xcodebuild -exportArchive  -archivePath "~/Desktop/TestArchive/GomeShop.xcarchive" -exportPath "~/Desktop/TestArchive/GomeShop.ipa" -exportOptionsPlist "~/Desktop/TestArchive/exprotOptionsPlist.plist"

同样,在导出包的时候,也可以不用证书和描述文件,如果不需要的话,可以把两个配置参数去掉,

exportOptionsPlist这个参数,它是一个plist文件。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>provisioningProfiles</key>
	<dict>
		<key>com.gomeshop.release</key>
		<string>Dist_GM_GomeMeishop</string>
	</dict>
	<key>teamID</key>
	<string>KYACQ4K486</string>
	<key>method</key>
	<string>app-store</string>
	<key> compileBitcode</key>
	<false/>
</dict>
</plist>

其他字段的描述

Available keys for -exportOptionsPlist:

    compileBitcode : Bool

        For non-App Store exports, should Xcode re-compile the app from bitcode? Defaults to YES.

    embedOnDemandResourcesAssetPacksInBundle : Bool

        For non-App Store exports, if the app uses On Demand Resources and this is YES, asset packs are embedded in the app bundle so that the app can be tested without a server to host asset packs. Defaults to YES unless onDemandResourcesAssetPacksBaseURL is specified.

    iCloudContainerEnvironment

        For non-App Store exports, if the app is using CloudKit, this configures the "com.apple.developer.icloud-container-environment" entitlement. Available options: Development and Production. Defaults to Development.

    manifest : Dictionary

        For non-App Store exports, users can download your app over the web by opening your distribution manifest file in a web browser. To generate a distribution manifest, the value of this key should be a dictionary with three sub-keys: appURL, displayImageURL, fullSizeImageURL. The additional sub-key assetPackManifestURL is required when using on demand resources.

    method : String

        Describes how Xcode should export the archive. Available options: app-store, ad-hoc, package, enterprise, development, and developer-id. The list of options varies based on the type of archive. Defaults to development.

    onDemandResourcesAssetPacksBaseURL : String

        For non-App Store exports, if the app uses On Demand Resources and embedOnDemandResourcesAssetPacksInBundle isn't YES, this should be a base URL specifying where asset packs are going to be hosted. This configures the app to download asset packs from the specified URL.

    teamID : String

        The Developer Portal team to use for this export. Defaults to the team used to build the archive.

    thinning : String

        For non-App Store exports, should Xcode thin the package for one or more device variants? Available options: <none> (Xcode produces a non-thinned universal app), <thin-for-all-variants> (Xcode produces a universal app and all available thinned variants), or a model identifier for a specific device (e.g. "iPhone7,1"). Defaults to <none>.

    uploadBitcode : Bool

        For App Store exports, should the package include bitcode? Defaults to YES.

    uploadSymbols : Bool

        For App Store exports, should the package include symbols? Defaults to YES.

完成上诉操作,就可以直接打包出.ipa包了。

学习博客:

https://www.cnblogs.com/sidesky/p/5102278.html

https://www.jianshu.com/p/2d1c6fdc88f2

https://www.jianshu.com/p/3f43370437d2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值