ReactNative入门教程及遇到的坑

来源:互联网 发布:装win10和linux双系统 编辑:程序博客网 时间:2024/05/22 08:11

这里推荐两个官方教程

1 React Native 官方文档

2 React Native 官方文档中文版


如果英文水平还可以,还是看英文版比较好,原因文档有最新版,还可以在线直接修改调试,对于初学者很快就能上手。

从我个人经验,来说入门RN最难的还是,对其架构原理的理解,已经开发环境的配置,毕竟需要React开发环境,IOS开发环境,Android开发环境才能看到所有的运行结果。

我在这个过程就遇到很多坑,虽然官方提供了几个命令行,就能快速初始化一个RN工程,但要运行起来,却往往遇到各种问题。

我遇到的坑及解决办法:


1 官方教程之坑

react-native init AwesomeProject
cd AwesomeProject


代码中已安装好node-module文件夹,但里面有坑


然后启动服务 npm start -- --reset-cache


然后运行IOS react-native run-ios


报错boost/iterator/iterator_adaptor.hpp’ file not found


网上找到 http://www.jianshu.com/p/d43b761c5f5c 以为能解决,确实这个错误解决了,但又报找不到 third-part中 config.h


后来解决方法
删除node-module文件夹
重新下载 npm install
之后编译过去了,但是出现红色页面,按提示重新安装一遍
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: `watchman watch-del-all`.
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
  3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cache`.
  
  

  2 jdshop之坑(一个开源项目)

  
  代码中未安装好node-module文件夹
  
  运行npm install
  
  第一个坑 node-module/react-native-svg中有react,重复冲突,删除其中的react
  第二个坑 React-Native-Webview-Bridge中引用React的方式有问题
  #import "RCTViewManager.h"改为#import <React/RCTViewManager.h>
  兼容的方式
  #if __has_include(<React/RCTViewManager.h>)
  #import <React/RCTViewManager.h>
  #else // back compatibility for RN version < 0.40
  #import "RCTViewManager.h"
  #endif


   错误提示:"Duplicate interface definition for class "'RCTView'" 
   讨论:https://github.com/airbnb/react-native-maps/issues/937
   
   尝试降级React及React-Native,但由于其他库的依赖,会产生新的问题,最后放弃


原创粉丝点击