美文网首页
iOS 自动打包App Store脚本

iOS 自动打包App Store脚本

作者: 1693c7e88afe | 来源:发表于2018-11-02 13:35 被阅读5次

    自动化打包方案:xcodebuild打包

      使用xcodebuild自动化打包给就是用命令行来控制Xcode进行编译打包
     xcodebuild打包有3种,一种是adHoc测试打包ipa;一个是上传AppStore打包;一个企业级别打包。具体区别请看下面的步骤中说明
    

    首先打开终端 cd到当前工程目录

     输入:  xcodebuild -list  可以看到 你的项目工程信息!
    

    屏幕快照 2018-11-02 下午1.11.24.png

    编译工程脚本:

    archive -workspace ${project_path}/${project_name}.xcworkspace \
    -scheme ${scheme_name} \
    -configuration ${development_mode} \
    -archivePath ${build_path}/${project_name}.xcarchive  -quiet  || exit```
    
    然后再打成IPA包
    xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \
    -configuration ${development_mode} \
    -exportPath ${exportIpaPath} \
    -exportOptionsPlist ${exportOptionsPlistPath} \
    -quiet || exit
    
    
    上传App Store
    #验证并上传到App Store
    # 将-u 后面的XXX替换成自己的AppleID的账号,-p后面的XXX替换成自己的密码
    altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
    "$altoolPath" --validate-app -f ${exportIpaPath}/${scheme_name}.ipa -u ${appid_email} -p ${appid_pwd} -t ios --output-format xml
    "$altoolPath" --upload-app -f ${exportIpaPath}/${scheme_name}.ipa -u  ${appid_email} -p ${appid_pwd} -t ios --output-format xml
    参数说明:
    project_path:项目路径
    project_name:项目名字
    exportIpaPath:输出路径iPad包
    development_mode:那种类型的包:Debug  Release
    appid_email:开发者账号
    appid_pwd:密码
    
    exportOptionsPlistPath:包.plist文件路径
    
    • Debug包:.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>provisioningProfiles</key>
        <dict>
            <key>自己的bundelId</key>
            <string>测试证书名字</string>
        </dict>
    </dict>
    </plist>
    
    • Release包:.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>destination</key>
        <string>export</string>
        <key>method</key>
        <string>app-store</string>
        <key>provisioningProfiles</key>
        <dict>
            <key>自己bundelId</key>
            <string>证书名字生产</string>
        </dict>
        <key>signingCertificate</key>
        <string>iPhone Distribution</string>
        <key>signingStyle</key>
        <string>manual</string>
        <key>stripSwiftSymbols</key>
        <true/>
        <key>teamID</key>
        <string>ZA8447H3V3</string>
        <key>uploadBitcode</key>
        <false/>
        <key>uploadSymbols</key>
        <true/>
    </dict>
    </plist>
    
    • 完整的shell脚本,里面还包含上传蒲公英的内容
    #使用方法
    
    if [ ! -d ./IPADir ];
    then
    mkdir -p IPADir;
    fi
    
    if [  -d ./build ];
    then
    rm -rf build;
    fi
    #更新说明
    MSG="蒲公英版本更新说明"
    build_number = "3"
    #工程绝对路径
    project_path=$(cd `dirname $0`; pwd)
    
    #苹果账号
    appid_email=xxx
    
    #密码
    appid_pwd=xxx
    
    #工程名 将XXX替换成自己的工程名
    project_name=xxx
    
    #scheme名 将XXX替换成自己的sheme名
    scheme_name=xxx
    
    #打包模式 Debug/Release
    development_mode=Debug
    
    #build文件夹路径
    build_path=${project_path}/build
    
    #plist文件所在路径
    exportOptionsPlistPath=${project_path}/packIpa/exportOptions.plist
    
    #导出.ipa文件所在路径
    exportIpaPath=${project_path}/IPADir/${development_mode}
    
    
    echo "Place enter the number you want to export ? [ 1:app-store 2:蒲公英] "
    
    ##
    read number
    while([[ $number != 1 ]] && [[ $number != 2 ]])
    do
    echo "Error! Should enter 1 or 2"
    echo "Place enter the number you want to export ? [ 1:app-store 2:蒲公英] "
    read number
    done
    
    if [ $number == 1 ];then
    development_mode=Release
    exportOptionsPlistPath=${project_path}/packIpa/exportOptions_dist.plist
    else
    development_mode=Debug
    exportOptionsPlistPath=${project_path}/packIpa/exportOptions.plist
    fi
    
    
    echo '///-----------'
    echo '/// 正在清理工程'
    echo '///-----------'
    xcodebuild \
    clean -configuration ${development_mode} -quiet  || exit
    
    
    echo '///--------'
    echo '/// 清理完成'
    echo '///--------'
    echo ''
    
    echo '///-----------'
    echo '/// 正在编译工程:'${development_mode}
    echo '///-----------'
    xcodebuild \
    archive -workspace ${project_path}/${project_name}.xcworkspace \
    -scheme ${scheme_name} \
    -configuration ${development_mode} \
    -archivePath ${build_path}/${project_name}.xcarchive  -quiet  || exit
    
    echo '///--------'
    echo '/// 编译完成'
    echo '///--------'
    echo ''
    
    echo '///----------'
    echo '/// 开始ipa打包'
    echo '///----------'
    xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \
    -configuration ${development_mode} \
    -exportPath ${exportIpaPath} \
    -exportOptionsPlist ${exportOptionsPlistPath} \
    -quiet || exit
    
    if [ -e $exportIpaPath/${scheme_name}.ipa ]; then
    echo '///----------'
    echo '/// ipa包已导出'
    echo '///----------'
    open $exportIpaPath
    else
    echo '///-------------'
    echo '/// ipa包导出失败 '
    echo '///-------------'
    fi
    echo '///------------'
    echo '/// 打包ipa完成  '
    echo '///-----------='
    echo ''
    
    echo '///-------------'
    echo '/// 开始发布ipa包 '
    echo '///-------------'
    
    if [ $number == 1 ];then
    
    #验证并上传到App Store
    # 将-u 后面的XXX替换成自己的AppleID的账号,-p后面的XXX替换成自己的密码
    altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
    "$altoolPath" --validate-app -f ${exportIpaPath}/${scheme_name}.ipa -u ${appid_email} -p ${appid_pwd} -t ios --output-format xml
    "$altoolPath" --upload-app -f ${exportIpaPath}/${scheme_name}.ipa -u  ${appid_email} -p ${appid_pwd} -t ios --output-format xml
    else
    
    #上传到蒲公英
    # 将XXX替换成自己的Fir平台的token
    echo "~~~~~~~~~~~~~~~~上传ipa到蒲公英~~~~~~~~~~~~~~~~~~~"
    curl -F "file=@${exportIpaPath}/${scheme_name}.ipa" \
    -F "uKey=xxxx" \
    -F "appVersionNo=${build_number}"
    -F "updateDescription=${MSG}" \
    -F "_api_key=xxxx" \
    https://qiniu-storage.pgyer.com/apiv1/app/upload
    
    if [ $? = 0 ]
    then
    echo -e "\n"
    echo "~~~~~~~~~~~~~~~~上传蒲公英成功~~~~~~~~~~~~~~~~~~~"
    else
    echo -e "\n"
    echo "~~~~~~~~~~~~~~~~上传蒲公英失败~~~~~~~~~~~~~~~~~~~"
    fi
    fi
    exit 0
    
    
    • 操作说明
    1. 脚本放到更目录中

    2.脚本运行:先输入:sh
    chmod +x ./test.sh #使脚本具有执行权限
    ./test.sh #执行脚本

    3.注意创建:exportOptions_dist.plist 和 exportOptions.plist 目录要注意和路径对应

    4.shell语法学习网站:http://www.runoob.com/linux/linux-shell.html

    相关文章

      网友评论

          本文标题:iOS 自动打包App Store脚本

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