搭建环境笔记记录:node
安装node, watchmanreact
brew install node
brew install watchman
复制代码
设置镜像加速android
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
复制代码
Watchman则是由 Facebook 提供的监视文件系统变动的工具。安装此工具能够提升开发时的性能(packager 能够快速捕捉文件的变化从而实现实时刷新)git
Yarn、React Native 的命令行工具(react-native-cli)github
Yarn是 Facebook 提供的替代 npm 的工具,能够加速 node 模块的下载。React Native 的命令行工具用于执行建立、初始化、更新项目、运行打包服务(packager)等任务。shell
npm install -g yarn react-native-cli
复制代码
安装完 yarn 后同理也要设置镜像源npm
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
复制代码
到固定的目录下建立项目文件夹react-native
react-native init AwesomeProject
复制代码
运行项目浏览器
cd AwesomeProject
react-native run-android
复制代码
运行 react-native start 是一直卡在 loading dependency graph...bash
最后出来 unable to talk to your watchman on /usr/local/var/run/watchman/xiuchengyin-state/sock
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
复制代码
最终HelloWorld页面起来了:
adb reverse tcp:8081 tcp:8081
adb reverse tcp:8081 tcp:8081
react-native run-android
复制代码
这样就OK了,其实上面添加assets的方案不知道啥意思,不推荐。
利用Chrome来调试:浏览器输入http://localhost:8081/debugger-ui, 而后右键 选择 检查打开调试,看到 console。
连上真机调试。