IOS应用构建:4:使用fastlane构建ipa文件

IOS应用构建:4:使用fastlane构建ipa文件_第1张图片
使用xcodebuild或者fastlane都可以对工程文件进行打包,这里针对前文创建的Object的示例工程给出使用fastlane创建示例语句。

fastlane

使用fastlane名为gym的action可实现打包的功能,比如可以参考如下示例代码:

liumiaocn:demo liumiao$ cat create_ipa.sh 
#!/bin/sh
PROJECT_NAME=demo
GYM_WORKSPACE=`pwd`/${PROJECT_NAME}.xcodeproj/project.xcworkspace
GYM_CONFIGURATION=Release
GYM_SCHEME=Shared
GYM_CLEAN=true
GYM_INCLUDE_BITCODE=false
GYM_INCLUDE_SYMBOLS=false
GYM_CODE_SIGNING_IDENTITY="[email protected]"
GYM_OUTPUT_DIRECTORY=target
GYM_OUTPUT_NAME=demo
GYM_BUILD_PATH=build
GYM_EXPORT_OPTIONS=

export FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT=60

fastlane gym\
    --workspace ${GYM_WORKSPACE}\
    --export_method=development\
    --configuration ${SIGN_TYPE}\
    --scheme ${GYM_SCHEME}\
    --clean ${GYM_CLEAN}\
    --include_bitcode ${GYM_INCLUDE_BITCODE}\
    --include_symbols ${GYM_INCLUDE_SYMBOLS}\
    --output_directory ${GYM_OUTPUT_DIRECTORY}\
    --output_name "${GYM_OUTPUT_NAME}"\
    --build_path ${GYM_BUILD_PATH}
liumiaocn:demo liumiao$ 

注:本示例根据fastlane内容整理,本机确认少Profile未能继续验证,使用时务必根据自己的工程和账号设定相关变量内容

常见问题

错误示例:缺少provisioning profile的配置信息

liumiaocn:demo liumiao$ sh create_ipa.sh 
[✔]  
[06:20:04]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[06:20:05]: $ xcodebuild -showBuildSettings -workspace /Users/liumiao/Documents/demo/demo.xcodeproj/project.xcworkspace -scheme demo -configuration --scheme
[06:20:06]: Couldn't automatically detect the provisioning profile mapping
[06:20:06]: Since Xcode 9 you need to provide an explicit mapping of what
[06:20:06]: provisioning profile to use for each target of your app
[06:20:06]: [Xcodeproj] Unable to open `/Users/liumiao/Documents/demo/demo.xcodeproj/demo.xcodeproj` because it doesn't exist.
[06:20:06]: Couldn't find specified configuration '--scheme'.

+------------------------+------------------------------------------------------------------+
|                                  Summary for gym 2.137.0                                  |
+------------------------+------------------------------------------------------------------+
| workspace              | /Users/liumiao/Documents/demo/demo.xcodeproj/project.xcworkspac  |
|                        | e                                                                |
| export_method          | development                                                      |
| clean                  | true                                                             |
| include_bitcode        | false                                                            |
| include_symbols        | false                                                            |
| output_directory       | target                                                           |
| output_name            | demo                                                             |
| build_path             | build                                                            |
| scheme                 | demo                                                             |
| destination            | generic/platform=iOS                                             |
| silent                 | false                                                            |
| skip_package_ipa       | false                                                            |
| result_bundle          | false                                                            |
| buildlog_path          | ~/Library/Logs/gym                                               |
| skip_profile_detection | false                                                            |
| xcode_path             | /Applications/Xcode.app                                          |
+------------------------+------------------------------------------------------------------+

[06:20:06]: $ set -o pipefail && xcodebuild -workspace /Users/liumiao/Documents/demo/demo.xcodeproj/project.xcworkspace -scheme demo -destination 'generic/platform=iOS' -archivePath build/demo\ 2019-12-14\ 06.20.06.xcarchive clean archive | tee /Users/liumiao/Library/Logs/gym/demo-demo.log | xcpretty
[06:20:08]: ▸ Clean Succeeded
[06:20:08]: ▸ ❌  error: Signing for "demo" requires a development team. Select a development team in the Signing & Capabilities editor. (in target 'demo' from project 'demo')
[06:20:08]: ▸ ** ARCHIVE FAILED **
▸ Clean Succeeded

❌  error: Signing for "demo" requires a development team. Select a development team in the Signing & Capabilities editor. (in target 'demo' from project 'demo')


** ARCHIVE FAILED **
[06:20:08]: Exit status: 65

原因:如提示所说,XCode 9需要显示地设定provisioning profile,此处是未选择Team,然后选择之后如果没有权限,仍然会执行出错。


此时执行,仍然会提示出错信息,因为此账户为免费的开发者账号,而在网站进行后续的操作。出错信息如下所示:

[06:32:41]: ▸ Clean Succeeded
[06:32:42]: ▸ ❌  error: No profiles for 'liumiao.com.demo' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'liumiao.com.demo'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'demo' from project 'demo')
[06:32:42]: ▸ ** ARCHIVE FAILED **
▸ Clean Succeeded

❌  error: No profiles for 'liumiao.com.demo' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'liumiao.com.demo'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'demo' from project 'demo')


** ARCHIVE FAILED **
[06:32:42]: Exit status: 65

对应方法:设定开发者账号,上传CSR,生成证书,然后在工程中添加账号,自动下载provisioning profile即可

memo

一个旧版的xcodebuild的构建方式的memo,在11.3下似乎已经无法使用,暂时memo一下

liumiaocn:demo liumiao$ cat xcode_create_ipa.sh 
#!/bin/sh

PROJECT_NAME=demo
CONFIGURATION=Release
WORKSPACE_NAME=`pwd`/${PROJECT_NAME}.xcodeproj/project.xcworkspace
SCHEME_NAME=Shared
ARCHIVE_PATH=target
EXPORT_PATH=${ARCHIVE_PATH}/${PROJECT_NAME}.xcarchive

xcodebuild clean -configuration ${CONFIGURATION} 

xcodebuild archive -workspace ${WORKSPACE} \
           -scheme ${SCHEME_NAME}          \
           -configuration ${CONFIGURATION} \
           -archivePath ${ARCHIVE_PATH}

xcodebuild -exportArchive                  \
           -archivePath ${ARCHIVE_PATH}    \
           -configuration ${CONFIGURATION} \
           -exportPath ${EXPORT_PATH}

liumiaocn:demo liumiao$ 

注:在11.3下提示参数使用不正确

你可能感兴趣的:(#,持续构建)