React Native下iOS和Android打包腳本

寫腳本打包的好處就不多說了,我前面也有寫相關(guān)的博客介紹,為了以后換了項(xiàng)目方便,我把腳本貼出來,做個(gè)記錄,以后稍作修改,就可以復(fù)用。
項(xiàng)目目錄:


目錄結(jié)構(gòu).png

同時(shí)打包腳本.png

同時(shí)打iOS和Android包并上傳

測試包
./pack.sh debug
預(yù)生產(chǎn)
./pack.sh pre
正式包
./pack.sh release

當(dāng)前目錄./pack.sh的代碼

cd android
./pack.sh $1
cd ../ios
./pack.sh $1

只打iOS或者Android包并上傳

進(jìn)入ios或者android目錄

測試包
./pack.sh debug
預(yù)生產(chǎn)
./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 開發(fā)者賬號 -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 開發(fā)者賬號 -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

知識點(diǎn):

xcodebuild打包
gradle打包
shell腳本
這里主要用到的shell命令就是參數(shù)的傳遞,內(nèi)容的替換,點(diǎn)擊這里學(xué)習(xí)下

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,023評論 25 709
  • React Native開發(fā)中自動打包腳本 在日常的RN開發(fā)中,我們避免不了需要將我們編寫的代碼編譯成安裝包,然后...
    光強(qiáng)_上海閱讀 3,385評論 3 25
  • 寫在前面 之前寫了一個(gè)很簡單的ipa打包腳本,主要是用Xcode命令中的xcodebuild和xcrun命令來完成...
    謙言忘語閱讀 12,258評論 27 63
  • “給我打個(gè)debug包,我測個(gè)功能點(diǎn)!”“給我打個(gè)release包,我測下線上環(huán)境!”“給我打個(gè)。。。。?!?但凡...
    HarwordLiu閱讀 2,662評論 35 6
  • 在我腦海中揮之不去的她 披著初及雙肩稍卷的頭發(fā) 背后是一個(gè)大大的奶油蛋糕一樣的太陽 發(fā)著微醺的晨光 輕風(fēng)把她的頭發(fā)...
    年輪止閱讀 242評論 0 0

友情鏈接更多精彩內(nèi)容