美文网首页ios 组件化
iOS 自动化打包(xcodebuild)

iOS 自动化打包(xcodebuild)

作者: 卟过尔尔 | 来源:发表于2020-05-09 14:44 被阅读0次

    为了方便自己,节约出时间。参考了很多大佬的文章,最后决定自己写一个,过程中还是踩到很多坑,所以在此写下...

    首先,要想学会自动化打包,就要先了解自动化打包所需要用到的工具及打包过程。

    工具

    xcodebuild,是苹果发布自动构建的工具

    打包命令

    在打包的过程中 实际使用到的命令 一共也就三个

    xcodebuild clean 清理工程

    xcodebuild archive 编译打包文件

    xcodebuild -exportArchive 导出IPA包

    其它命令

    man xcodebuild 可以看到xcodebuild常用命令

    xcodebuild --help 可以看到xcodebuild的使用实例

    xcodebuild -list 可以看到工程的Target ,scheme,configuration配置参数

    open ~/Library/MobileDevice/Provisioning\ Profiles 可以查看描述文件

    /usr/bin/security cms -D -i xxx.mobileprovision 可以查看描述文件具体信息

    Demo

    图一中是一个简单的demo,包括了项目目录(build.sh、exprotOptionsPlist.plist)及2个自动化打包成功后的文件,这里本人使用的是个人开发者账号

    图一

    build.sh文件代码

    #!bin/sh
    
    echo "开始工程清理"
    # ${workspace} 工程中,.xcworkspace的文件名字
    # ${scheme} 当前要编译运行的scheme
    # configuration ${Debug或者Release} 当前是要以Debug运行还是以Release运行
    # -quiet 忽略警告提示打印
    # -UseNewBuildSystem=NO 是否使用新的build系统
    xcodebuild clean -workspace "SetUpConfiguartion.xcworkspace" -scheme "SetUpConfiguartion" -configuration Release -UseNewBuildSystem=NO
    echo "工程清理完成"
    
    echo "开始工程打包"
    #${workspace} 工程中,.xcworkspace的文件名字
    #${scheme} 当前要编译运行的scheme
    #configuration ${Debug或者Release} 当前是要以Debug运行还是以Release运行
    #-archive_path 导出.xcarchive文件的存放路径
    #CODE_SIGN_IDENTITY 证书文件名
    #PROVISIONING_PROFILE 运行文件UUID
    xcodebuild archive -workspace "SetUpConfiguartion.xcworkspace" -scheme "SetUpConfiguartion" -configuration Release -archivePath "~/Desktop/Configuartion/SetUpConfiguartion"
    echo "工程打包完成"
    
    echo "开始导出IPA包"
    #xcodebuild -exportArchive -archivePath archive文件的地址.xcarchive
    #                          -exportPath 导出的ipa文件夹地址
    #                          -exportOptionsPlist exprotOptionsPlist.plist(前面路径会自动补全)
    #                          CODE_SIGN_IDENTITY=证书
    #                          PROVISIONING_PROFILE=描述文件UUID
    xcodebuild -exportArchive -archivePath "~/Desktop/Configuartion/SetUpConfiguartion.xcarchive" -exportPath "~/Desktop/Configuartion/SetUpConfiguartion.ipa" -exportOptionsPlist "exprotOptionsPlist.plist"
    

    exprotOptionsPlist.plist代码

    <?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>53CCQ5M733</string>
        <key>method</key>
        <string>ad-hoc</string>
        <key>compileBitcode</key>
        <false/>
    </dict>
    </plist>
    
    

    执行命令

    项目路径下 终端输入sh ./build.sh

    遇到的问题

    ** ARCHIVE FAILED **
    
    The following build commands failed:
        Ld /Users/yq/Library/Developer/Xcode/DerivedData/SetUpConfiguartion-fljdbuqzrprylkdpzcjpkqnprygz/Build/Intermediates.noindex/ArchiveIntermediates/SetUpConfiguartion/IntermediateBuildFilesPath/SetUpConfiguartion.build/Release-iphoneos/SetUpConfiguartion.build/Objects-normal/armv7/Binary/SetUpConfiguartion normal armv7
    (1 failure)
    工程打包完成
    开始导出IPA包
    error: archive not found at path '/Users/yq/Desktop/Configuartion/SetUpConfiguartion.xcarchive'
    ** EXPORT FAILED **
    
    

    解决方法:
    pod install (normal arm64)

    ** ARCHIVE SUCCEEDED **
    
    工程打包完成
    开始导出IPA包
    error: Couldn't load -exportOptionsPlist: The file “exprotOptionsPlist.plist” couldn’t be opened because there is no such file.
    
    Error Domain=NSCocoaErrorDomain Code=260 "The file “exprotOptionsPlist.plist” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/yq/Desktop/Configuartion/SetUpConfiguartion/~/Desktop/Configuartion/SetUpConfiguartion/exprotOptionsPlist.plist, NSUnderlyingError=0x7fd56ecc6b30 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
    
    ** EXPORT FAILED **
    

    解决方法:NSFilePath=/Users/yq/Desktop/Configuartion/SetUpConfiguartion/~/Desktop/Configuartion/SetUpConfiguartion/exprotOptionsPlist.plist
    这里提示路径错误
    xcodebuild -exportArchive 中的 -exportOptionsPlist 路径不需要写全,会自动补全,写名称就可以了

    ** ARCHIVE SUCCEEDED **
    
    工程打包完成
    开始导出IPA包
    2020-05-09 11:33:57.289 xcodebuild[20203:817143] [MT] IDEDistribution: -[IDEDistributionLogging _createLoggingBundleAtPath:]: Created bundle at path '/var/folders/_6/t0xhscld37g6mb17jt4cv2sw0000gn/T/SetUpConfiguartion_2020-05-09_11-33-57.287.xcdistributionlogs'.
    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/_6/t0xhscld37g6mb17jt4cv2sw0000gn/T/ipatool-json-filepath-~~~EygMH8}
    
    ** EXPORT FAILED **
    

    解决方法:
    首页可以前往文件 /var/folders/_6/t0xhscld37g6mb17jt4cv2sw0000gn/T/SetUpConfiguartion_2020-05-09_11-33-57.287.xcdistributionlogs 中查看日志找到具体原因

    Error Domain=NSCocoaErrorDomain Code=3840 "No value."
    检查下
    <key>compileBitcode</key>
    <false/>

    ** ARCHIVE FAILED **
    
    
    The following build commands failed:
        CompileStoryboard /Users/yq/Desktop/Configuartion/SetUpConfiguartion/SetUpConfiguartion/Base.lproj/LaunchScreen.storyboard
    (1 failure)
    工程打包完成
    开始导出IPA包
    error: archive not found at path '/Users/yq/Desktop/Configuartion/SetUpConfiguartion.xcarchive'
    ** EXPORT FAILED **
    

    解决方案:
    删除LaunchScreen.storyboard文件,改为Assets.xcassets中增加LaunchImage.launchimage

    学习博客

    https://blog.csdn.net/ioszhanghui/article/details/91375973
    https://www.jianshu.com/p/3f43370437d2
    https://blog.csdn.net/ioszhanghui/article/details/91046928

    相关文章

      网友评论

        本文标题:iOS 自动化打包(xcodebuild)

        本文链接:https://www.haomeiwen.com/subject/fbghnhtx.html