这几天折腾了jenkins对iOS swift项目的持续集成,碰到了很多问题,记录下吧

1. 缺少scheme

xcodebuild: error: The project named “Foo” does not contain a scheme named “Bar”. The “-list” option can be used to find the names of the schemes in the project.

解决办法:
The root cause is that the default behavior of Schemes is to keep schemes ‘private’ until they are specifically marked as shared. In the case of a command-line initiated build, the Xcode UI never runs and the xcoderun tool doesn’t have its own cache of Schemes to work with.
To your schema be visible for command-line build you must mark it as a shared scheme.

Choose Scheme > Manage Schemes (from the Product Menu).
Ensure the ‘Shared’ box is checked for that scheme
A new .xcscheme file has been created in your project at
WorkspaceName.xcworkspace/xcshareddata/xcschemes.
Commit this file to your repository

2. Error: User interaction is not allowed.

运行下面的命令可解决

$ security unlock-keychain -p  ~/Library/Keychains/login.keychain
$ security show-keychain-info ~/Library/Keychains/login.keychain
Keychain "/Users/XXX/Library/Keychains/login.keychain" no-timeout

3. Xcode 7后导出IPA命令发生变化

以前我是通过下面的命令打包的,但现在的swift项目这样导出的包在iPhone安装后直接闪退

xcodebuild -target ${TARGET_NAME} -configuration ${BUILD_CONFIGURATION} -sdk phones build
xcrun -sdk iphoneos PackageApplication -v ${APP_NAME} -o ${IPA_PATH}

Xcode7之后取消了原来的-exportFormat,而是使用exportOptionsPlist 来取代,具体的使用方法可以在Terminal打xcodebuild –help查看。
我们需要自己创建一个plist作为Export Options,只要有这个配置文件,那我们在使用这个命令的时候就能打出跟手动用Xcode Archive之后export出的ipa一样了。

<?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>teamID</key>
  <string>XXXXXXX</string>
  <key>method</key>
  <string>enterprise</string>
  <key>compileBitcode</key>
  <false/>
  <key>uploadSymbols</key>
  <false/>
</dict>
</plist>

4. 最新的xcodebuild 导出ipa命令

xcodebuild archive -project {xcodeproj} -scheme '{scheme}' -sdk iphoneos  -archivePath {archive_path}
xcodebuild -exportArchive -archivePath  {archive_path} -exportPath {export_path}  -exportOptionsPlist {export_plist_path}

[本文独立博客地址](http://www.offbye.com

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐