一直是从事iOS的开发,现在研究下mac环境下reatNative的环境配置:
1. 安装HomeBlew(OS系统上的一个安装包管理器,安装后可以方便后续安装包的安装。)
终端命令:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. 安装Node.js (服务端的JavaScript运行环境)
下载地址:https://nodejs.org/download/
成功安装后,终端会有如下提示信息:
Node.js was installed at: /usr/local/bin/node
npm was installed at: /usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.
3. 建议安装WatchMan(React修改source文件的一个工具)
终端命令:
brew install watchman
4. 安装Flow: 一个JavaScript 的静态类型检查器。
终端命令:
brew install flow
5. 安装React Native CLI: 用来开发React Native的命令行工具
终端命令:
npm install -g react-native
创建项目1. 新建一个项目
新建一个“HelloWorld”的项目,每个语言的开始教程都是这个,我们也不例外。
操作超级简单,只需终端输入命令行:
react-native init HelloWorld
这样就新建了一个工程,前往文件夹:/用户/xxx/HelloWorld (xxx为电脑用户名),打开iOS文件下的工程:
注意:打开后会报以下错误
❌ error: Build input file cannot be found:'/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/strtod.cc'▸ Compiling fast-dtoa.cc
❌ error: Build input file cannot be found:'/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/fast-dtoa.cc'▸ Compiling fixed-dtoa.cc
❌ error: Build input file cannot be found:'/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/fixed-dtoa.cc'▸ Compilingdouble-conversion.cc
❌ error: Build input file cannot be found:'/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/double-conversion.cc'▸ Compiling diy-fp.cc
❌ error: Build input file cannot be found:'/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/diy-fp.cc'▸ Compiling cached-powers.cc
❌ error: Build input file cannot be found:'/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/cached-powers.cc'▸ Compiling bignum.cc
❌ error: Build input file cannot be found:'/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/bignum.cc'
解决方案
cd node_modules/react-native/scripts && ./ios-install-third-party.sh &&cd../../../
cd node_modules/react-native/third-party/glog-0.3.5/ && ../../scripts/ios-configure-glog.sh