ReactNative环境搭建

React Native环境搭建

前期准备环境

brew 安装

brew 在官方网站对brew的用法进行了详细的描述,是一款更方便的下载软件库的软件,类似于centos的yum。
安装方法:在Mac中打开Termal: 输入命令

1
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
使用方法:
1
2
3
brew install wget
brew uninstall wget
brew search /wge*/

node.js 安装

以下是官方定义:
1
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
1
nmp 是 node的一个三方管理工具,相当于 Ruby中的RubyGems,iOS中的 CocoaPods,Java中的 Gradle/Maven,基本上,它使您能够轻松下载和管理你的项目需要的任何依赖库。
安装方法:

  • 官方下载安装
  • 通过brew安装
    1
    brew install node

react-navtive等的安装:

接下来安装watchman
1
brew install watchman
接下来安装react-native-cli(如果权限不足需要sudo)
1
npm install -g react-native-cli
创建第一个项目并运行
1
react-native init FirstReactNative --verbose(能看到详细信息和进度,就是npm的安装进度)
成功后控制打印
1
2
3
4
5
6
7
8
9
10
This will walk you through creating a new React Native project in /Users/rplees/work/git/react-native/FirstReactNative
Installing react-native package from npm...
Setting up new React Native app in /Users/rplees/work/git/react-native/FirstReactNative
To run your app on iOS:
Open /Users/rplees/work/git/react-native/FirstReactNative/ios/FirstReactNative.xcodeproj in Xcode
Hit the Run button
To run your app on Android:
Have an Android emulator running (quickest way to get started), or a device connected
cd /Users/rplees/work/git/react-native/FirstReactNative
react-native run-android
运行 ios
1
Now open any example (the .xcodeproj file in each of the Examples subdirectories) and hit Run in Xcode.(需要打开xcode编译项目再运行)

运行 android 需要安装 Android SDK

1
react-native run-android
运行watchman的时候抛错
1
2
3
4
5
6
7
8
9
10
192:FirstReactNative rplees$ sudo watchman
Password:
dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
Referenced from: /usr/local/bin/watchman
Reason: image not found
192:FirstReactNative rplees$ npm uninstall watchman
192:FirstReactNative rplees$ watchman
dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
Referenced from: /usr/local/bin/watchman
Reason: image not found
经过一番搜索,发现是pcre找不到,通过如下命令即可修复:
1
brew uninstall pcre && brew install pcre
运行npm start的时候抛错
1
2
3
TypeError: Cannot read property 'root' of null
这个问题困扰很久,后来才发现是watchman版本的问题
brew update && brew upgrade watchman 就解决了

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 rplees.i.ly@gmail.com

文章标题:ReactNative环境搭建

本文作者:rplees

发布时间:2016-01-14, 11:20:58

最后更新:2019-07-16, 15:59:49

原始链接:http://rplees.com/2016/01/14/react-native环境搭建/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏