ReactNative打離線包-android篇
離線包就是把RN和你寫的js圖片等資源都打包放入app,不需要走網路下載。
打包命令說明:
react-native bundle
Options:
--entry-file Path to the root JS file, either absolute or relative to JS root [required]
--platform Either "ios" or "android"
--transformer Specify a custom transformer to be used (absolute path) [default: "/Users/babytree-
mbp13/projects/xcodeProjects/AwesomeProject/node_modules/react-native/packager/transformer.js"]
--dev If false, warnings are disabled and the bundle is minified [default: true]
--prepack If true, the output bundle will use the Prepack format. [default: false]
--bridge-config File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex.
./bridgeconfig.json
--bundle-output File name where to store the resulting bundle, ex. /tmp/groups.bundle [required]
--bundle-encoding Encoding the bundle should be written in
([https://nodejs.org/api/buffer.html#buffer_buffer).]
(https://nodejs.org/api/buffer.html#buffer_buffer).) [default: "utf8"]
--sourcemap-output File name where to store the sourcemap file for resulting bundle, ex.
/tmp/groups.map
--assets-dest Directory name where to store assets referenced in the bundle
--verbose Enables logging [default: false]
安卓打包步驟
1、在工程根目錄下執行打包命令,比如
react-native bundle --entry-file index.android.js --bundle-output ./android/app/src/main/assets/index.android.bundle --platform android --assets-dest ./android/app/src/main/res/ --dev false
其中--entry是入口js檔案,android系統就是index.android.js,ios系統就是index.ios.js,--bundle-output就是生成的bundle檔案路徑,--platform是平臺,--assets-dest是圖片資源的輸出目錄,這個在後面的圖片增量更新中會用到,--dev表示是否是開發版本,打正式版的安裝包時我們將其賦值為false。
請參考上面命令說明,根據自己的情況進行修改再執行。注意要先保證[./android/app/src/main/assets/]資料夾存在。
2、命令執行完生成如下資源
3、修改MainApplication檔案,設定BundleAssetName
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override protected boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; }
@Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage() ); }
@Nullable @Override protected String getBundleAssetName() { return "index.android.bundle"; }
};
4、通過Android Studio打包即可(也可通過命令打包)
生成的apk在 \android\app\build\outputs\apk
其他
To disable the developer menu for production builds:
For iOS open your project in Xcode and select Product → Scheme → Edit Scheme... (or press ⌘ + <). Next, select Run from the menu on the left and change the Build Configuration to Release.
For Android, by default, developer menu will be disabled in release builds done by gradle (e.g with gradle assembleRelease task). Although this behavior can be customized by passing proper value to ReactInstanceManager#setUseDeveloperSupport.
參考連結:https://segmentfault.com/a/1190000004192816
官方文件:http://facebook.github.io/react-native/docs/running-on-device-android.html#content
官方文件2:http://facebook.github.io/react-native/docs/signed-apk-android.html#content
相關文章
- RN精進筆記(六)RN打離線包篇筆記
- Android Studio module 打aar包Android
- 【Android Build】高效批量打渠道包AndroidUI
- Android APK打渠道包實施方案AndroidAPK
- Android ReactNative資料互動AndroidReact
- Android Studio使用離線GradleAndroidGradle
- 區塊鏈錢包-android篇區塊鏈Android
- Android Studio 3.1.1 打Jar包出現AGPBI異常AndroidJAR
- Springboot 打jar包分離lib,配置檔案正確方式Spring BootJAR
- vue-cli3打包後分離配置檔案Vue
- ReactNative原始碼篇:通訊機制React原始碼
- python離線安裝外部依賴包Python
- 區塊鏈錢包開發(Android篇)區塊鏈Android
- python(pip)包/模組:如何離線安裝?Python
- 純小白uni-app+Android Studio離線打包APPAndroid
- echarts 地圖 免費離線js,json包分享Echarts地圖JSON
- 谷歌瀏覽器下載離線安裝包谷歌瀏覽器
- macOS monterey 12系統離線pkg安裝包Mac
- 堅果雲for Android支援離線預覽office嗎?Android
- MacOS 13.0b2 離線系統安裝包Mac
- 【手把手學習flutter】Flutter打Android包的基本配置和包體積優化策略FlutterAndroid優化
- MacOS 11-13.x離線安裝包 通用版Mac
- rhel9.2離線下載安裝包,並安裝
- Maven專案打jar包MavenJAR
- 芋道Springboot打war包Spring Boot
- macos 10.15系統正式版離線安裝包:macOS CatalinaMac
- KubeKey v3.1 釋出:快速自定義離線安裝包
- MacOS 11.x-12.x完整離線安裝包 (新增Monterey)Mac
- VS2017社群版離線包百度雲資源
- 從Android到ReactNative開發(二、通訊與模組實現)AndroidReact
- 從Android到ReactNative開發(三、自定義原生控制元件支援)AndroidReact控制元件
- Nessus下載離線升級包all-2.0 .tar.gz方法
- jenkins 打安卓包失敗Jenkins安卓
- springboot專案打war包流程Spring Boot
- java打jar包的maven方式JavaJARMaven
- AIOS原定計劃上線兩大交易所進行推遲 將聯合上線離線錢包AIiOS
- [實戰] Android 撥打電話Android
- 印表機離線了怎麼連線 印表機離線的連線方法
- SpringBoot配置外部Tomcat並打war包Spring BootTomcat