Shell脚本-IOS/Android打包

效果图

控制台执行shell脚本命令 注意cd到文件路径哈

sh  HelloWorldBuild.sh

项目目录 

 控制台CD到项目目录执行 xcodebuild -list 、 xcodebuild -showsdks 可以看到一些配置信息

HelloWorldBuild.sh

_PROJECT_WORKSPACE="helloworlds.xcworkspace"

_PROJECT_OUTPUT_PATH="/Users/znan/Build/HelloWorld"

_CODE_SIGN_IDENTITY="iPhone Distribution: ******"

_PROVISIONING_PROFILE="*********"


echo "\033[31;1mstarting -----------------------> \033[0m"

echo "\033[36;1mchoose scheme \033[0m"
echo "\033[33;1m1. HelloWorld \033[0m"
echo "\033[33;1m2. HelloWorld TW \033[0m"
echo "\033[33;1m3. HelloWorld HK \033[0m"
read schemeType
scheme=‘’
if [ $schemeType -eq 1 ]; then
scheme='HelloWorld'
elif [ $schemeType == 2 ]; then
scheme='HelloWorld TW'
elif [ $schemeType == 3 ]; then
scheme='HelloWorld HK'
else
echo "\033[31;1mNo scheme type defined, execution terminated \033[0m"
exit
fi


echo "\033[36;1mchoose configuration environment \033[0m"
echo "\033[33;1m1. UAT \033[0m"
echo "\033[33;1m2. Prepord \033[0m"
echo "\033[33;1m3. Production \033[0m"
read configurationType
configuration=''
if [ $configurationType -eq 1 ]; then
configuration='UAT'
elif [ $configurationType == 2 ]; then
configuration='Prepord'
elif [ $configurationType == 3 ]; then
configuration='Production'
else
echo "\033[31;1mNo configuration type defined, execution terminated \033[0m"
exit
fi


echo "\033[31;1mcleaning -----------------------> \033[0m"
xcodebuild clean -workspace ${_PROJECT_WORKSPACE} -scheme "${scheme}" -configuration "${configuration}"

echo "\033[31;1mBuilding-----------------------> \033[0m"
exportPath="${_PROJECT_OUTPUT_PATH}/${configuration}/${scheme}/helloworld_archive" | sed 's/ //g'
xcodebuild archive -workspace ${_PROJECT_WORKSPACE} -scheme "${scheme}" -configuration "${configuration}" -archivePath ${exportPath} CODE_SIGN_IDENTITY=${_CODE_SIGN_IDENTITY} PROVISIONING_PROFILE=${_PROVISIONING_PROFILE}

echo "\033[31;1mPacking-----------------------> \033[0m"
xcodebuild -exportArchive -archivePath "${exportPath}.xcarchive" -exportPath ${exportPath} -exportOptionsPlist "helloworldExport.plist"

echo "\033[32;1mSuccess-----------------------> \033[0m"
echo "Path: ${exportPath}"
open ${exportPath}

helloworldExport.plist

参照正常打包流程生成的ExportOptions.plist就明白参数了

_CODE_SIGN_IDENTITY的值: 

钥匙串访问-右键显示简介 --> 标题名字

 

 _PROVISIONING_PROFILE的值:

通过命令行查看mobileprovision信息:
/usr/bin/security cms -D -i "path/******.mobileprovision"

另外搞点有颜色的

30:黑
31:红
32:绿
33:黄
34:蓝色
35:紫色
36:深绿
37:白色

差不多应该就是这样了....搞Android的尽力了.....

接下来是android的

# sh build.sh
workdir="$(
  cd $(dirname $0)
  pwd
)"
targetFileDir="$workdir/sgs/build/outputs/aar"
sitFileDir="$targetFileDir/sgs-sit.aar"
releaseFileDir="$targetFileDir/sgs-release.aar"
echo "\033[36;1m Choose configuration environment \033[0m"
echo "\033[33;1m1. Sit \033[0m"
echo "\033[33;1m2. Release \033[0m"
echo "\033[33;1m3. Sit and Release \033[0m"
read configurationType
echo "\033[35;1m Modify 'build.gradle' start-----------------------> \033[0m"
cd sgs || exit
line=$(sed -n '/SGS_VERSION/=' build.gradle)
for i in $line; do
  content=$(sed -n "${i}p" build.gradle)
  array=(${content//,/ })
  lastVersion=${array[3]}
  version=${lastVersion//"\""/""}
  version=${version//"'"/""}
  versionCodeArray=(${version//./ })
  lastVersionCode=${versionCodeArray[2]}
  versionCode=$(expr $lastVersionCode + 1)
  targetVersion="${versionCodeArray[0]}.${versionCodeArray[1]}.$versionCode"
  sed -i '' "${i}s/$version/$targetVersion/" build.gradle
done
echo "\033[35;1m Modify 'build.gradle' e n d-----------------------> \033[0m"
cd ..
echo "\033[31;1m Start building -----------------------> \033[0m"
configuration=''
if [ "$configurationType" -eq 1 ]; then
  configuration='Sit'
  ./gradlew -p sgs clean
  ./gradlew -p sgs assembleSit
  cd "$targetFileDir" || exit
  zip -j "sgs-sit.zip" "$sitFileDir"
elif [ "$configurationType" == 2 ]; then
  configuration='Release'
  ./gradlew -p sgs clean
  ./gradlew -p sgs assembleRelease
  cd "$targetFileDir" || exit
  zip -j "sgs-release.zip" "$releaseFileDir"
elif [ "$configurationType" == 3 ]; then
  configuration='Sit and Release'
  ./gradlew -p sgs clean
  ./gradlew -p sgs assembleSit
  ./gradlew -p sgs assembleRelease
  cd "$targetFileDir" || exit
  zip -j "sgs-sit.zip" "$sitFileDir"
  zip -j "sgs-release.zip" "$releaseFileDir"
else
  echo "\033[31;1m No configuration type defined, execution terminated \033[0m"
  exit
fi
open "$targetFileDir"
echo "\033[32;1m Success build $configuration -----------------------> \033[0m"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值