项目开发中经常会遇到打包,企业版打包或者是真机打包,每次打包都是对自己都是一种考验,自动化打包其实很简单,简单了解下xCode编译的命令即可.
简介
xcrun和xcodebuild是苹果提供的打包项目或者工程的命令,简单看下版本号:
xcrun -version
xcrun version 30.
xcodebuild版本号:
xcodebuild -version
Xcode 8.1
Build version 8B62
man xcodebuild查看一些基本参数配置:
xcodebuild [-project name.xcodeproj] -scheme schemename
[[-destination destinationspecifier] ...]
[-destination-timeout value]
[-configuration configurationname]
[-sdk [sdkfullpath | sdkname]] [action ...]
[buildsetting=value ...] [-userdefault=value ...]
①打包之前获取archive包:
xcodebuild archive -project BuildDemo.xcodeproj -scheme BuildDemo -configuration Debug -archivePath ~/Desktop/BuildApp/BuildDem
configuration Debug和Release模式,project 是一般项目配置,如果项目通过pod引入第三方需要使用-workspace.
②获取ipa文件:
xcodebuild -exportArchive -archivePath ~/Desktop/BuildApp/BuildDemo.xcarchive -exportPath ~/Desktop/BuildApp/BuildDemo
自动化打包
#!/bin/bash
PRODUCTNAME="BuildDemo"
SCHEME="BuildDemo"
PRODUCTMODE="Debug"
EXPORTDIR="~/Desktop/BuildApp/"
EXPORTNAME="BuildDemo"
#Clean
xcodebuild clean
# Build Project
xcodebuild archive -project $PRODUCTNAME.xcodeproj \
-scheme $SCHEME \
-configuration $PRODUCTMODE \
-archivePath $EXPORTDIR$EXPORTNAME | xcpretty
echo $EXPORTDIR$EXPORTNAME.xcarchive
#Archive ipa
xcodebuild -exportArchive -archivePath $EXPORTDIR$EXPORTNAME.xcarchive -exportPath $EXPORTDIR$EXPORTNAME | xcpretty
echo 'FlyElephant'
关于打包之间的两步还可以通过PackageApplication来实现:
xcodebuild -project $PRODUCTNAME.xcodeproj -target $SCHEME -configuration Debug
xcrun -sdk iphoneos -v PackageApplication ./build/$PRODUCTMODE-iphoneos/$PRODUCTNAME.app -o $EXPORTDIR$EXPORTNAME.ipa