使用的打包命令:
xcodebuild archive -workspace $project_name.xcworkspace -scheme $project_name -configuration Release -archivePath archive/$project_name.xcarchive CODE_SIGN_IDENTITY="iPhone Developer: xxxxxx (xxxxxxx)" PROVISIONING_PROFILE_SPECIFIER="development_orange"
echo "第五步,執(zhí)行編譯生成.ipa命令"
xcodebuild -exportArchive -exportOptionsPlist archieveOpt.plist -archivePath archive/$project_name.xcarchive -exportPath ./ -configuration Release
打包命令在這里不多做解釋,主要說一下遇到的兩個坑.
參考文章:
第三方庫使用 Framework,用 Jenkins 打包時報錯
坑一:Podfile 文件中使用了 use_frameworks!造成的坑
如果Podfile 文件中使用了 use_frameworks,那么Jenkins打包時出現(xiàn)以下錯誤
Check dependencies
Code Signing Error: AFNetworking does not support provisioning profiles. AFNetworking does not support provisioning profiles, but provisioning profile development_orange has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor.
這是因為使用了 use_frameworks后,CocoaPods 要對每一個 Framework 進(jìn)行證書簽名,而每個 Framework 的 bundleID 都是不一樣的
解決方案:
在 Podfile 中添加如下代碼:
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
添加后的podfile文件如下:
platform :ios, '8.0'
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
target 'QingPu' do
? ? pod 'MBProgressHUD'
? ? pod 'MJExtension','~> 3.0.13'
? ? pod 'MJRefresh'
? ? pod 'ReactiveObjC'
? ? pod 'FMDB', '~> 2.7.2'
end
坑二:Archive成功,export ipa文件時失敗,報以下錯誤:error: exportArchive: The data couldn’t be read because it isn’t in the correct format?
Error Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value., NSFilePath=/var/folders/7p/06ytfm5n5f35z9d4byf0q1_c00007x/T/ipatool-json-filepath-lgeLRm}
第五步,執(zhí)行編譯生成.ipa命令
2018-05-18 15:22:27.811 xcodebuild[32828:2936854] [MT] IDEDistribution: Step failed: : Error Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value., NSFilePath=/var/folders/7p/06ytfm5n5f35z9d4byf0q1_c00007x/T/ipatool-json-filepath-lgeLRm}
error: exportArchive: The data couldn’t be read because it isn’t in the correct format.
Error Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value., NSFilePath=/var/folders/7p/06ytfm5n5f35z9d4byf0q1_c00007x/T/ipatool-json-filepath-lgeLRm}
** EXPORT FAILED **
這是因為配置文件archieveOpt.plist中compileBitcode選項沒有配置,默認(rèn)compileBitcode為YES,要設(shè)置成NO就可以了,archieveOpt.plist配置后的樣式如下:

再次打包就可以了
坑三:jenkins 自動構(gòu)建 IOS 包簽名遇到問題 ??app: errSecInternalComponent?Command /usr/bin/codesign failed with exit code 1
解決辦法:
?編譯之前添加 security unlock-keychain -p "你的密碼" "path to keychain/login.keychain"
根本原因是Jenkins,ssh方式到slave機(jī)上,默認(rèn)是沒有賬戶的,但是訪問鑰匙串要求必須有用戶身份,所以添加一步輸入密碼解鎖鑰匙串,可以給Jenkins一個用戶身份。 build步驟前添加一步解鎖鑰匙串。?security unlock-keychain -p "login pwd" ~/Library/Keychains/login.keychain