美文网首页
iOS打包脚本

iOS打包脚本

作者: 灰斗儿 | 来源:发表于2019-08-22 20:20 被阅读0次

脚本源自网络搜集

脚本一


#!/bin/bash
# 
#--------------------------------------------
# 功能:
# 作者:
# 创建日期:
#--------------------------------------------
 
#上传服务器配置
appId="0001"
versionId="1.0.0"
uploadUrl="http://*********/test/upload.json"
 
#证书及描述文件
CODE_SIGN_IDENTITY="iPhone Distribution: *** Appliance Co., Ltd."
DEVELOPMENT_TEAM="5E2PGY2377***"
PROVISIONING_PROFILE_SPECIFIER="****Enterprise"
 
#打包环境检测
if [ $1 != "sit" -a $1 != "pre" -a $1 != "Pre" -a $1 != "pre2" -a $1 != "Pre2" -a $1 != "pre3" -a $1 != "Pre3" -a $1 != "prd" ]; then
    echo "请输入正确的构建环境:[sit | pre | Pre | pre2 | Pre2 | pre3 | Pre3 | prd]"
    exit 1
else
    build_env=$(echo $1 | perl -pe 's/.*/\u$&/')    
fi
 
#工程路径读取
workspace_path="$(cd "$(dirname $0)" && pwd)"
cd ${workspace_path}
workspace_name=$(ls | grep xcworkspace)
project_dir="epa_project_ios"
project_path=${workspace_path}/${project_dir}
project_name=$(ls ${project_dir} | grep xcodeproj | awk -F.xcodeproj '{print $1}')
target_name=${project_name}
info_plist=${project_path}/Project/${project_name}-Info.plist
result_path=${workspace_path}/build/${build_env}_$(date +%Y-%m-%d_%H_%M)
 
#工程代码更新
echo "======开始更新代码======"
cd ${project_path}
git stash
git pull --rebase
cd ${workspace_path}
pod update --no-repo-update --verbose
if [ $? != 0 ]; then
    echo "======代码更新失败======"
    exit 1
else
    echo "======完成代码更新======"
fi
 
#修改版本号
if [ -n "$2" ]; then
    bundleShortVersion=$(echo $2 | perl -pe 's/.*/\u$&/')
    /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${bundleShortVersion}" ${info_plist}
else
    #主版本号读取
    bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${info_plist})
fi
 
#应用标识及名称修改
case "$1" in
    sit|pre|pre2|pre3)
        bundle_identifier=com.suning.${build_env}
        bundle_name=${build_env}${bundleShortVersion}
        ;;
    Sit|Pre|Pre2|Pre3|Prd|prd)
        bundle_identifier=com.suning.SuningEfubao
        bundle_name="****test"
    ;;
esac
 
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier ${bundle_identifier}" ${info_plist}
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName ${bundle_name}" ${info_plist}
 
#Today Extension
te_info_plist=${project_path}/NotificationBarForYiFuBao/Info.plist
if [ -f ${nse_info_plist} ]; then
    te_bundle_identifier=${bundle_identifier}.NSExtension
    /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier ${te_bundle_identifier}" ${te_info_plist}
fi
 
#Notification Service Extension
nse_info_plist=${project_path}/NotificationServiceExtension/Info.plist
if [ -f ${nse_info_plist} ]; then
    nse_bundle_identifier=${bundle_identifier}.NotificationServiceExtension
    /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier ${nse_bundle_identifier}" ${nse_info_plist}
fi
 
#打包环境修改
config_file=${project_path}/Project/Src/Constants/BuildConfig.h
 
if [ -f ${config_file} ]; then
 
    upper_env=$(echo ${build_env} | tr '[a-z]' '[A-Z]')
 
    echo "======修改环境配置======"
    sed -i '' "/TARGET_ENV_/ s/1/0/" ${config_file}
    sed -i '' "/TARGET_ENV_${upper_env}/ s/0/1/" ${config_file}
 
    sed -i '' "/DEBUG_ENABLE/ s/1/0/" ${config_file}
    
fi
 
#构建路径设置
mkdir -p "${result_path}"
setting_out=${result_path}/build_setting.txt
xcodebuild -showBuildSettings -workspace "${workspace_name}" -scheme "${target_name}" -configuration Release > ${setting_out}
build_path=`echo $(grep -w  "CONFIGURATION_BUILD_DIR" ${setting_out} | awk -F= '{print $2}')`
echo "======build_path: ${build_path}======"
archive_path=${build_path}/${target_name}.xcarchive
 
 
#清除旧包
rm -rf ${archive_path}
#归档打包
echo "======开始构建======"
xcodebuild clean archive -workspace "${workspace_name}" \
-scheme "${target_name}" \
-archivePath ${archive_path} \
-configuration Release \
CODE_SIGN_IDENTITY="${CODE_SIGN_IDENTITY}" \
DEVELOPMENT_TEAM="${DEVELOPMENT_TEAM}" \
PROVISIONING_PROFILE_SPECIFIER="${PROVISIONING_PROFILE_SPECIFIER}"
 
echo "======检查是否构建成功======"
if [ -d "${archive_path}" ]; then
    
    echo "构建成功......"
    
else
 
    echo -e "\033[31m 构建失败,请修正后重新运行! \033[0m"
    rm -rf ${result_path}
    exit 1
 
fi
 
cd ${project_path}
git checkout -- ${config_file}
git checkout -- ${info_plist}
git checkout -- SNYifubao.xcodeproj/project.pbxproj
 
ipa_name=${target_name}_${bundleShortVersion}.ipa
ipa_path=${result_path}
ExportOptionsPlist=${project_path}/ExportOptions.plist
 
#XCODE8 需要使用系统的ruby
which rvm > /dev/null
if [[ $? -eq 0 ]]; then
    echo "RVM detected, forcing to use system ruby"
    [ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"
    rvm use system
fi
 
#导出ipa
xcodebuild -exportArchive \
-archivePath ${archive_path} \
-exportOptionsPlist ${ExportOptionsPlist} \
-exportPath ${ipa_path}
 
echo "======检查是否成功导出ipa======"
ipa_temp_path=${ipa_path}/${target_name}.ipa
if [ -f "${ipa_temp_path}" ]; then
    echo "导出ipa成功......"
    #ipa重命名
    mv "${ipa_temp_path}" "${ipa_path}/${ipa_name}"
else
    echo -e "\033[31m 导出ipa失败...... \033[0m"
    exit 1
fi
 
#备份dSYM
dsym_path=${archive_path}/dSYMs/${target_name}.app.dSYM/Contents/Resources/DWARF/${target_name}
cp -R "${dsym_path}" "${result_path}/${target_name}.dSYM"
 
#info名称
ipa_info=${target_name}_${bundleShortVersion}.info
echo ${target_name} ${bundleShortVersion} $1"($(date "+%Y-%m-%d %H:%M"))" > ${result_path}/${ipa_info}
ipaDesc="****test"$1
 
echo "======result_path: ${result_path}======"
 
###########################################文件上传###########################################
 
echo "======开始上传测试包======"
case "$build_env" in
Pre|Pre2|Pre3)
build_env="Pre";;
esac
cd ${result_path}
#curl -T "{${ipa_name},${ipa_info}}" -u epp:ios ftp://*********/${build_env}/ipa/
 
 
curl -F "appId=${appId}" -F "versionId=${versionId}" -F "bundleId=${bundle_identifier}" -F "ipaDesc=${ipaDesc}" -F "ipaFile=@${ipa_path}/${ipa_name}" ${uploadUrl}
 
echo "======共耗时${SECONDS}秒======"
 ———————————————— 
版权声明:本文为CSDN博主「lxlmycsdnfree」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lxlmycsdnfree/article/details/81015455

相关文章

  • Xcode自动打包

    [iOS]从零开始写个自动打包IPA脚本 【iOS打ipa包】:使用终端实现自动打包 iOS自动打包并发布脚本

  • iOS自动打包ipa(shell脚本)

    系列 iOS自动打包ipa(shell脚本)iOS自动打包ipa(Python脚本) 安装xctool shell...

  • iOS自动打包ipa(Python脚本)

    系列 iOS自动打包ipa(shell脚本)iOS自动打包ipa(Python脚本) 安装Python库 Pyth...

  • iOS脚本一键打包

    ios打包脚本的使用 相关链接: 1. IOS工程自动打包并发布脚本的实现。 2. Xcode中Command L...

  • 2019-02-15

    ios打包时签名失败 ios打包时证书和provisioningprofile都已经切换更新,打包脚本中指定tea...

  • iOS自动打包脚本

    iOS自动打包脚本 iOS自动打包脚本,并实现图片素材、文字资源、部分代码的替换和重签名,基于python实现。 ...

  • ios-面试-脚本打包原理

    脚本打包,自然是为了方便打包,便于ios开发不用手动打包,便于非ios开发能去打包! 打包过程 Xcode打包的过...

  • iOS面试题:脚本打包

    脚本打包,自然是为了方便打包,便于ios开发不用手动打包,便于非ios开发能去打包! 打包过程 Xcode打包的过...

  • iOS开发知识体系之《脚本自动化打包--xcodebuild》

    iOS脚本自动化打包方案--xcodebuild 本文主要xcodebuild脚本自动化打包并上传到蒲公英或者Ap...

  • App itunes connect 提交审核"UIR

    解决方案 xcodebuild 来自iOS自动打包并发布脚本

网友评论

      本文标题:iOS打包脚本

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