iOS 打包工具生成

时间:2021-01-03 18:38:06

预备知识:要懂shell脚本和xcode命令行命令,libexec命令使用

1、首先根据序号选择对应的证书,这个要在自己的配置文件中写好

while read var

do

case "$var"in

1)

selectIndex=$var

echo "==is number=="

break

;;

*)echo "==is no number=="

;;

esac

done

2、读配置文件,设置证书和证书的ID,启动图片和应用程序的图标

while read myline

do

rightDistributionSign=`echo $myline | awk -F':' '{print $3}'`

echo $rightDistributionSign


rightProvision=`echo $myline | awk -F':' '{print $4}'`

echo $rightProvision


bundleIdentifier=`echo $myline | awk -F':' '{print $2}'`

echo $bundleIdentifier


bundleDisplayName=`echo $myline | awk -F':' '{print $5}'`

echo $bundleDisplayName


appicon=`echo $myline | awk -F':' '{print $6}'`

echo $appicon


launchimage=`echo $myline | awk -F':' '{print $7}'`

echo $launchimage


thisapp=`echo $myline | awk -F':' '{print $8}'`

echo $thisapp

break

fi

done <$full_path

修改plist文件中配置

#设置bundleIdentifier

/usr/libexec/PlistBuddy -c "set CFBundleIdentifier ${bundleIdentifier}" ${info_plist}


#设置bundleDisplayName

/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName ${bundleDisplayName}" ${info_plist}


3、进行打包

xcodebuild -project ${project_path}/xxx.xcodeproj CODE_SIGN_IDENTITY="${rightDistributionSign}" PROVISIONING_PROFILE="${rightProvision}" ASSETCATALOG_COMPILER_APPICON_NAME="${xxxxxxxx}"  ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME="${xxxxxx}" -configuration Distribution  -sdk iphoneos CODE_SIGN_RESOURCE_RULES_PATH='$(SDKROOT)/ResourceRules.plist' -target"${target_name}" clean


#编译工程

xcodebuild -project ${project_path}/xxx.xcodeproj CODE_SIGN_IDENTITY="${rightDistributionSign}" PROVISIONING_PROFILE="${rightProvision}" ASSETCATALOG_COMPILER_APPICON_NAME="${xxxxxxxxx}"  ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME="${xxxxxxxx}" -configuration Distribution  -sdk iphoneos CODE_SIGN_RESOURCE_RULES_PATH='$(SDKROOT)/ResourceRules.plist'  -target "${target_name}" build


build_result=$?


# 编译失败

if [ ${build_result} -ne0 ]; then

echo -e "\033[31m 编译失败,请修正后重新构建! \033[0m"

exit

fi


#build文件夹路径

build_path=${project_path}/build/Release-iphoneos

echo "======编译路径:${build_path}======"

#打包完的程序目录

appDir=${build_path}/${target_name}.app

#dSYM的路径

dsymDir=${build_path}/${target_name}.app.dSYM/Contents/Resources/DWARF/${target_name}

#ipa名称

ipa_name=${target_name}_${bundleShortVersion}_app.ipa

ipa_path="${result_path}/${ipa_name}"

xcrun -sdk iphoneos PackageApplication -v"${appDir}" -o "${ipa_path}"

#拷贝dSYM放在子目录

cp -R "${dsymDir}""${result_path}/${target_name}.dSYM"


这样打包完成。