React Native下iOS和Android打包脚本

写脚本打包的好处就不多说了,我前面也有写相关的博客介绍,为了以后换了项目方便,我把脚本贴出来,做个记录,以后稍作修改,就可以复用。
项目目录:


目录结构.png

同时打包脚本.png

同时打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命令就是参数的传递,内容的替换,点击这里学习下

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,612评论 25 708
  • React Native开发中自动打包脚本 在日常的RN开发中,我们避免不了需要将我们编写的代码编译成安装包,然后...
    光强_上海阅读 3,278评论 3 25
  • 写在前面 之前写了一个很简单的ipa打包脚本,主要是用Xcode命令中的xcodebuild和xcrun命令来完成...
    谦言忘语阅读 12,122评论 27 62
  • “给我打个debug包,我测个功能点!”“给我打个release包,我测下线上环境!”“给我打个。。。。。” 但凡...
    HarwordLiu阅读 2,601评论 35 6
  • 在我脑海中挥之不去的她 披着初及双肩稍卷的头发 背后是一个大大的奶油蛋糕一样的太阳 发着微醺的晨光 轻风把她的头发...
    年轮止阅读 232评论 0 0