ReactNative打离线包-android篇

发布时间:2019-06-22 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了ReactNative打离线包-android篇脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

官方文档: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和你写的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). [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]

安卓打包步骤

    @H_360_38@

    在工程根目录下执行打包命令,比如 react-native bundle --entry-file demo/index.js --bundle-output ./android/app/src/main/assets/index.andROId.jsbundle --platform android --assets-dest ./android/app/src/main/res/ --dev false 请参考上面命令说明,根据自己的情况进行修改再执行。注意要先保证[./android/app/src/main/assets/]文件夹存在。

  1. 命令执行完生成资源如图

    ReactNative打离线包-android篇

  2. 保证MainActivity.java中的setBundleAssetName与你的jsbundle文件名一致,比如.setBundleAssetName("index.android.jsbundle")就与我生成的资源名一致

  3. 一切OK 打包测试吧

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.

脚本宝典总结

以上是脚本宝典为你收集整理的ReactNative打离线包-android篇全部内容,希望文章能够帮你解决ReactNative打离线包-android篇所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。