由于项目需要,增加效率,选择接入了Jenkins可持续打包工具来实现这一目的。网上有很多iOS jenkins打包教程,包括jenkins安装的过程,所以,具体的过程我就不做详细叙述了,我也推荐两篇教程给大家:
参考:https://www.jianshu.com/p/047ac4c39297
https://www.jianshu.com/p/8b2fc2da0466
以下记录了 ,我集成jenkins时的一些配置,和遇到的问题,给遇到类似问题的小伙伴一个参考,少走一些弯路(里面的坑确实比较多),我目前踩到成功打包,后续还有上传到发布平台,文章会继续记录。
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的项目需要这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
# 项目打包命令
# 工程名
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
#获取权限
security unlock-keychain -p "电脑授权密码" $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 项目问题:如果在 ~/Library/Keychains 中找不到 login.keychain 文件
获取login.keychain文件路径: ~/Library/Keychains/ 找到 login.keychain-db 直接将
login.keychain , 再上传的jenkins
获取电脑中Provisioning Profiles 文件的路径 :~/Library/MobileDevice/
并将其配置文件粘贴到jenkins 的 /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
后面根据对比发现新版的Xcode少了这个PackageApplication(转注:PackageApplication在前几个版本已被标识为废弃,在8.3版本彻底移除了)
先去找个旧版的Xcode里面copy一份过来
放到下面这个目录:
- /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/
然后执行命令:(2句分开执行)
- 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项目打开manage schemes 在选中的targets后选中shared
5Q、出现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 选项,在下面的Porvisioning Profile 中选中打包的配置文件,重新提交git仓库
网友评论