使用 xcodebuild 和 xcrun 自动化打包

xcodebuild 编译项目

xcodebuild -scheme $scheme_name -configuration $build_config -target $scheme_name -sdk iphoneos -derivedDataPath ./build || echo "Build iphonesimulator $APPLICATION_NAME.app failed!"

xcrun 对编译结果打包

xcrun -sdk iphoneos PackageApplication -v "${RELEASE_BUILDDIR}/${APPLICATION_NAME}.app" -o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" --sign "${DEVELOPER_NAME}" --embed "${PROVISONING_PROFILE}"


出现的问题:

集成证书错误

Error:

error: Unable to copy '~/Desktop/iphone_MyApp_adhoc.mobileprovision' to '/var/folders/4s/pbnz61195rx434zz_gqj85gr0000gn/T/yXUJsrYvne/Payload/MyApp.app/embedded.mobileprovision

授权文件的路径不正确,这里需要改成绝对路径就可以了。

Codesign 签名错误

Error:
/usr/bin/codesign returned 1 : [iPhone Developer: Name (XJWYTGSWM4): ambiguous (matches "iPhone Developer: Name (XJWYTGSWM4)" and "iPhone Developer: Name (XJWYTGSWM4)" in /Users/xxx/Library/Keychains/login.keychain)

原因是keychain 中有重复的证书文件,导致无法找到正确的证书 Stackoverflow 的解答