首页新闻招聘找找看知识库
  • 浏览:34 2019-01-07 14:40 来自 甘林梦

    通过shell脚本实现从archive->生成ipa->上传到第三方平台(Fir.im 、蒲公英)或 App store

    通过下面几步即可实现自动打包上传功能。

        

    .sh文件
    shell.sh
    
    
    #使用方法
    
    if [ ! -d ./IPADir ];
    then
    mkdir -p IPADir;
    fi
    
    #工程绝对路径
    project_path=$(cd `dirname $0`; pwd)
    
    #工程名 将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}/exportTest.plist
    
    #导出.ipa文件所在路径
    exportIpaPath=${project_path}/IPADir/${development_mode}
    
    
    echo "Place enter the number you want to export ? [ 1:app-store 2:ad-hoc] "
    
    ##
    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:ad-hoc] "
    read number
    done
    
    if [ $number == 1 ];then
    development_mode=Release
    exportOptionsPlistPath=${project_path}/exportAppstore.plist
    else
    development_mode= Debug
    exportOptionsPlistPath=${project_path}/exportTest.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 XXX -p XXX -t ios --output-format xml
    "$altoolPath" --upload-app -f ${exportIpaPath}/${scheme_name}.ipa -u  XXX -p XXX -t ios --output-format xml
    else
    # 上传IPA到蒲公英 XXX换成你在蒲公英获取的`uKey` 和 `_api_key`
    echo '-----------------------------'
    echo '|     上传IPA到蒲公英   |'
    echo '-----------------------------'
    curl -F "file=@"${exportIpaPath}"/"${scheme_name}.ipa \
    -F "uKey=XXX" \
    -F "_api_key=XXX" \
    https://www.pgyer.com/apiv2/app/upload
    #    open https://www.pgyer.com
    
    ##上传到Fir
    ## 将XXX替换成自己的Fir平台的token
    #fir login -T XXX
    #fir publish $exportIpaPath/$scheme_name.ipa
    
    fi
    
    exit 0
    // exportAppstore.plist  导出到App Store 
    
    
    <?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>xxx</key>
            <string>xxx</string>
        </dict>
        <key>method</key>
        <string>app-store</string>
        <key>uploadBitcode</key>
        <true/>
        <key>uploadSymbols</key>
        <true/>
    </dict>
    </plist>
    // exportTest.plist  上传蒲公英 用的
    // provisioningProfiles 是xcode 9 必填的  
    <?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>compileBitcode</key>
        <true/>
        <key>uploadSymbols</key>
        <true/>
        <key>uploadBitcode</key>
        <true/>
        <key>provisioningProfiles</key>
        <dict>
            <key>xxx</key>
            <string>xxx</string>
        </dict>
        <key>method</key>
        <string>ad-hoc</string>
    </dict>
    </plist>
    • 将三个文件拖入工程的根目录
    • 根据自己需求选择好描述文件
    • 根据自己的项目修改一下shell.sh
    • cd到工程根目录,通过./shell.sh 执行脚本即可

    IOS 一键打包发布脚本

    iOS- 一键自动打包发布到Fir和AppStore

     Xcode9报错解决

     
登录后才能评论,请先登录注册