React Native学习

ReactNative打离线包-Android篇

2018-07-10  本文已影响9人  街角仰望

离线包就是把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]

打包步骤

1、在工程根目录下执行打包命令:react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.jsbundle --assets-dest android/app/src/main/res/

2、cd android && ./gradlew installRelease

注意:RN0.5以后自动打包,只需要做步骤2就可以了

打包遇到的问题

1、文件夹错误


说明:文件夹为空,删除出错的文件夹即可。

2、签名冲突


说明:模拟器上安装的APP和打包APP签名不同导致冲突,卸载掉模拟器上的APP即可。

成功

安装包存放位置如图所示:


上一篇 下一篇

猜你喜欢

热点阅读