React Native安裝步驟
前期準(zhǔn)備
- 安裝Homebrew
mac OS X 軟件安裝包管理工具
$ curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install - 安裝node.js 4.0或更高版本
- 安裝nvm
- $ nvm install node && nvm alias default node
- 安裝watchman
facebook的開(kāi)源項(xiàng)目,用來(lái)監(jiān)視文件并記錄文件的改動(dòng)情況
$ brew install watchman - 安裝flow
$ brew install flow
安裝react native
- 敲入命令行
$ npm install -g react-native-cli - 選擇路徑創(chuàng)建工程:
$ react-native init AwesomeProject
這段時(shí)間會(huì)比較長(zhǎng)侄非,需要下載一些初始化文件 - 運(yùn)行:
Android:$ react-native run-android
Q&A
1. 啟動(dòng)node server報(bào)錯(cuò)
Failed to build DependencyGraph: Cannot read property 'root' of nullTypeError: Cannot read property 'root' of null at index.js:16:60
at tryCallOne (/Users/liying/react_test/node_modules/react-native/node_modules/promise/lib/core.js:37:12)
at /Users/liying/react_test/node_modules/react-native/node_modules/promise/lib/core.js:123:15
at flush (/Users/liying/react_test/node_modules/react-native/node_modules/promise/node_modules/asap/raw.js:50:29)
at doNTCallback0 (node.js:430:9)
at process._tickCallback (node.js:359:13)~
Process terminated. Press <enter> to close the window
解決方案:
- $ brew update
-
$ brew upgrade watchman
如果在此過(guò)程中遇到報(bào)錯(cuò):
Error: The /usr/local directory is not writable.
Even if this directory was writable when you installed Homebrew, other
software may change permissions on this directory. Some versions of the
"InstantOn" component of Airfoil are known to do this.
You should probably change the ownership and permissions of /usr/local
back to your user account.
sudo chown -R $(whoami):admin /usr/local
則輸入:*$ sudo chown -R liying:admin /usr/local *
2. 模擬器運(yùn)行報(bào)錯(cuò)
ReferenceError-Can-t-find-variable-fbBatchedBridge
可能原因:模擬器與js服務(wù)器不在同一網(wǎng)段蕉汪,無(wú)法訪問(wèn)服務(wù)器。
解決辦法:打開(kāi)模擬器中的settings逞怨,wifi設(shè)置中選擇WiredSSID鏈接者疤。
如果在真機(jī)上,搖一搖調(diào)出設(shè)置menu叠赦,選擇Dev Setting驹马,選擇Debug server host & port for device革砸,確保真機(jī)與電腦在同一網(wǎng)段,輸入電腦IP+服務(wù)器默認(rèn)端口號(hào)(8081) eg. 10.180.141.23:8081