網站首頁 編程語言 正文
1, 背景
如果我們打開RN的Android源碼,在build.gradle中回看到這樣一段代碼。
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
此段代碼的含義是,如果開啟了就采用新的hermes,如果未開啟則采用老的jsc加載引擎。Hermes 是專門針對 React Native 應用而優化的全新開源 JavaScript 引擎。對于很多應用來說,啟用 Hermes 引擎可以優化啟動時間,減少內存占用以及空間占用。
2,熱更新傳統方案
在傳統的熱更新方案中,我們實現熱更新需要借助code-push開源方案,熱更新包的發布有兩種方式:
- code-push release-react:打bundle并自動上傳
- code-push release:需先打bundle,再通過該命令上傳
如果采用code-push release-reactapp熱更新后,殺掉進程重新進入,app首屏加載的時候速度會很慢,甚至可能出現白屏。這是因為生成的bundle只是通過babel編譯轉碼,然后經過js壓縮和削減,代碼的執行效率并不高。
而開啟Hermes引擎后,可以執行純文本的 JS 代碼,效率比替換js引擎前更低,執行效率也更高。
3,使用Hermes打包
首先,我們執行react-native bundle命令進行打包,比如。
react-native bundle --platform android --entry-file index.android.js --bundle-output ./bundles/index.android.bundle --assets-dest ./bundles --dev false
接下來,我們需要將bundle轉成字節碼。轉化前,我們需要先下載hermes-engine。
npm i hermes-engine
接著,執行如下命令將bundle轉換成字節碼
cd node_modules/hermes-engine/oxs-bin
./hermesc -emit-binary -out index.android.bundle.hbc /Users/xxxx/work/react-native/app/bundles/index.android.bundle
將之前bundle目錄下的index.android.bundle刪掉,將當前的index.android.bundle.hbc重命名為index.android.bundle,再移動到之前bundle目錄下。最后,使用下面的命令執行 bundle熱更新包的發布。
code-push release AndroidAppNamexx ./bundles 1.0.0 --d Staging --des "描述" --m true
使用這種方式后,下次有熱更新的時候,加載的速度比之前也有明顯的提升,特別是bundle包內容比較大的時候。
原文鏈接:https://blog.csdn.net/xiangzhihong8/article/details/124835758
相關推薦
- 2022-05-12 C++深淺拷貝和string類的兩種寫法詳解_C 語言
- 2022-01-29 composer global require “fxp/composer-asset-plugin
- 2022-08-03 sql注入報錯之注入原理實例解析_數據庫其它
- 2022-09-10 C#中AutoResetEvent控制線程用法小結_C#教程
- 2022-06-20 Android?Flutter實現點贊效果的示例代碼_Android
- 2021-12-06 c#二叉樹存儲介紹_C#教程
- 2022-05-20 關于Mybatis-plus中PaginationInterceptor分頁攔截器過時問題解決辦法
- 2022-07-11 python中的多cpu并行編程_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支