写脚本打包的好处就不多说了,我前面也有写相关的博客介绍,为了以后换了项目方便,我把脚本贴出来,做个记录,以后稍作修改,就可以复用。
项目目录:
同时打iOS和Android包并上传
测试包
./pack.sh debug
预生产
./pack.sh pre
正式包
./pack.sh release
当前目录./pack.sh的代码
cd android
./pack.sh $1
cd ../ios
./pack.sh $1
只打iOS或者Android包并上传
进入ios或者android目录
测试包
./pack.sh debug
预生产
./pack.sh pre
正式包
./pack.sh release
ios 目录下./pack.sh的代码
configuration=''
scheme=Baima
appDelegatePath="./${scheme}/AppDelegate.m"
archivePath="./${scheme}.xcarchive"
if test $1 == 'debug'
then
configuration='Debug'
elif test $1 == 'pre'
then
configuration='Pre'
elif test $1 == 'release'
then
configuration='Release'
else
echo "命令无效"
exit 2
fi
echo "hello, ${configuration} 开始打包"
echo $archivePath
cd ..
react-native bundle --entry-file index.js --bundle-output ./ios/bundle/index.ios.jsbundle --platform ios --assets-dest ./ios/bundle --dev false
cd ./ios
sed -i "" 's|jsCodeLocation = \[\[RCTBundleURLProvider sharedSettings\] jsBundleURLForBundleRoot:@"index" fallbackResource:nil\];|jsCodeLocation = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"index.ios.jsbundle" ofType:nil]];|g' $appDelegatePath
xcodebuild archive -scheme ${scheme} -configuration $configuration -archivePath $archivePath
if test $1 == 'release'
then
sed -i "" 's/development/app-store/' ./debug.plist
else
echo ''
fi
xcodebuild -exportArchive -archivePath $archivePath -exportPath ./Pack -exportOptionsPlist debug.plist
if test $1 == 'release'
then
echo "hello, ${configuration} Ok"
/Applications/Xcode9.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool --validate-app -f ./Pack/Baima.ipa -t ios -u 开发者账号 -p 密码 -t ios
/Applications/Xcode9.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool --upload-app -f ./Pack/Baima.ipa -t ios -u 开发者账号 -p 密码
else
curl -F "file=@./Pack/Baima.ipa" -F "uKey=蒲公英获取" -F "_api_key=蒲公英获取" https://qiniu-storage.pgyer.com/apiv1/app/upload
fi
git checkout -- $appDelegatePath
rm -rf $archivePath ./Pack
sed -i "" 's/app-store/development/' ./debug.plist
echo "hello, ${configuration} Ok"
android 目录下./pack.sh的代码
if test $1 == 'debug'
then
command='assembleDebug'
path='debug/app-debug.apk'
elif test $1 == 'pre'
then
command='assemblePre'
path='pre/app-pre.apk'
elif test $1 == 'release'
then
command='assembleRelease'
path='release/app-release.apk'
else
echo "命令无效"
exit 2
fi
cd ..
mkdir android/app/src/main/assets/
react-native bundle --entry-file index.js --platform android --dev false --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
cd ./android
gradle $command
curl -F "file=@./app/build/outputs/apk/$path" -F "uKey=蒲公英获取" -F "_api_key=蒲公英获取" https://qiniu-storage.pgyer.com/apiv1/app/upload
知识点:
xcodebuild打包
gradle打包
shell脚本
这里主要用到的shell命令就是参数的传递,内容的替换,点击这里学习下