由于項(xiàng)目需要,增加效率,選擇接入了Jenkins可持續(xù)打包工具來實(shí)現(xiàn)這一目的。網(wǎng)上有很多iOS jenkins打包教程,包括jenkins安裝的過程,所以,具體的過程我就不做詳細(xì)敘述了,我也推薦兩篇教程給大家:
參考:http://www.itdecent.cn/p/047ac4c39297
http://www.itdecent.cn/p/8b2fc2da0466
以下記錄了 ,我集成jenkins時的一些配置,和遇到的問題,給遇到類似問題的小伙伴一個參考,少走一些彎路(里面的坑確實(shí)比較多),我目前踩到成功打包,后續(xù)還有上傳到發(fā)布平臺,文章會繼續(xù)記錄。
Jenkins
啟動命令 :
- sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist
停止命令:
- sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
MAC下 Jenkins 升級:
- 通過路徑 ~/applications/Jenkins 找到本地的的 Jenkins.war , 把下載下來的Jenkins.war替換掉原本的
- 通過命令重啟Jenkins
打包的shell 命令:
# 安裝cocoaPod(用cocoapod的項(xiàng)目需要這4行命令)
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
pod install --verbose --no-repo-update
# 項(xiàng)目打包命令
# 工程名
APP_NAME="工程名"
# 證書
CODE_SIGN_DISTRIBUTION="簽證"
# info.plist路徑
project_infoplist_path="./${APP_NAME}/Info.plist"
#取版本號
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${project_infoplist_path}")
#取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}")
DATE="$(date +%Y%m%d)"
IPANAME="${APP_NAME}_V${bundleShortVersion}_${DATE}.ipa"
#要上傳的ipa文件路徑
IPA_PATH="$HOME/${IPANAME}"
echo ${IPA_PATH}
echo "${IPA_PATH}">> text.txt
#獲取權(quán)限
security unlock-keychain -p "電腦授權(quán)密碼" $HOME/Library/Keychains/login.keychain
# //下面2行是沒有Cocopods的用法
# echo "=================clean================="
# xcodebuild -target "${APP_NAME}" -configuration 'Release' clean
# echo "+++++++++++++++++build+++++++++++++++++"
# xcodebuild -target "${APP_NAME}" -sdk iphoneos -configuration 'Release' CODE_SIGN_IDENTITY="${CODE_SIGN_DISTRIBUTION}" SYMROOT='$(PWD)'
#//下面2行是集成有Cocopods的用法
echo "=================clean================="
xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${APP_NAME}" -configuration 'Release' clean
echo "+++++++++++++++++build+++++++++++++++++"
xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${APP_NAME}" -sdk iphoneos -configuration 'Release' CODE_SIGN_IDENTITY="${CODE_SIGN_DISTRIBUTION}" SYMROOT='$(PWD)'
xcrun -sdk iphoneos PackageApplication "./Release-iphoneos/${APP_NAME}.app" -o ~/"${IPANAME}"
Jenkins 打包時報錯
1Q、Jenkins 打包 iOS 項(xiàng)目問題:如果在 ~/Library/Keychains 中找不到 login.keychain 文件
獲取login.keychain文件路徑: ~/Library/Keychains/ 找到 login.keychain-db 直接將
login.keychain , 再上傳的jenkins
獲取電腦中Provisioning Profiles 文件的路徑 :~/Library/MobileDevice/
并將其配置文件粘貼到j(luò)enkins 的 /Users/Shared/Jenkins/Library/MobileDevice/ 路徑下
如果沒有MobileDevice就新建一個
2Q、第三方庫使用 Framework,用 Jenkins 打包時報錯:AFNetworking does not support provisioning profiles. AFNetworking does not support provisioning profiles, but provisioning profile getgetsetset5CommonTest has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. 等等第三方庫報錯
在podfile 文件的use_frameworks! 后面加入
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
end
end
end
3Q、Jenkins 打包時報錯
xcrun: error: unable to find utility "PackageApplication", not a developer tool or in PATH
后面根據(jù)對比發(fā)現(xiàn)新版的Xcode少了這個PackageApplication(轉(zhuǎn)注:PackageApplication在前幾個版本已被標(biāo)識為廢棄,在8.3版本徹底移除了)
先去找個舊版的Xcode里面copy一份過來
放到下面這個目錄:
- /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/
然后執(zhí)行命令:(2句分開執(zhí)行)
- sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/
- chmod +x /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication
PackageApplication文件傳送門: https://pan.baidu.com/s/1CV1bTSrO1xH4x9Kvjox0DQ 密碼: q4uz
4Q、error : The workspace named "工程名" does not contain a scheme named "工程名". The "-list" option can be used to find the names of the schemes in the workspace.
xcode項(xiàng)目打開manage schemes 在選中的targets后選中shared
5Q、出現(xiàn)ERROR:Set the code signing identity value to "iPhone Developer" in the build settings editor, or switch to manual signing in the project editor.
在Xcode的general中去掉Automatically manage signing 選項(xiàng),在下面的Porvisioning Profile 中選中打包的配置文件,重新提交git倉庫