D:\Workspace\ReactNative\Android>react-native init MyProject
This will walk you through creating a new React Native project in D:\Workspace\R
eactNative\Android\MyProject
Installing react-native package from npm...
> utf-8-validate@1.2.1 install D:\Workspace\ReactNative\Android\MyProject\node_m
odules\react-native\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild
D:\Workspace\ReactNative\Android\MyProject\node_modules\react-native\node_module
s\ws\node_modules\bufferutil>if not defined npm_config_node_gyp (node "D:\Progra
mFiles\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin
\node-gyp.js" rebuild ) else (node rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT
HON env variable.
gyp ERR! stack at failNoPython (D:\ProgramFiles\nodejs\node_modules\npm\node
_modules\node-gyp\lib\configure.js:116:14)
gyp ERR! stack at D:\ProgramFiles\nodejs\node_modules\npm\node_modules\node-
gyp\lib\configure.js:71:11
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:82:15)
gyp ERR! System Windows_NT 6.1.7600
gyp ERR! command "D:\\ProgramFiles\\nodejs\\node.exe" "D:\\ProgramFiles\\nodejs\
\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\Workspace\ReactNative\Android\MyProject\node_modules\react-nativ
e\node_modules\ws\node_modules\utf-8-validate
gyp ERR! node -v v4.2.6
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT
HON env variable.
gyp ERR! stack at failNoPython (D:\ProgramFiles\nodejs\node_modules\npm\node
_modules\node-gyp\lib\configure.js:116:14)
gyp ERR! stack at D:\ProgramFiles\nodejs\node_modules\npm\node_modules\node-
gyp\lib\configure.js:71:11
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:82:15)
gyp ERR! System Windows_NT 6.1.7600
gyp ERR! command "D:\\ProgramFiles\\nodejs\\node.exe" "D:\\ProgramFiles\\nodejs\
\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\Workspace\ReactNative\Android\MyProject\node_modules\react-nativ
e\node_modules\ws\node_modules\bufferutil
gyp ERR! node -v v4.2.6
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
npm WARN optional dep failed, continuing utf-8-validate@1.2.1
npm WARN optional dep failed, continuing bufferutil@1.2.1
`npm install --save react-native` failed
D:\Workspace\ReactNative\Android>
如果是连真机的话,很大可能看到的结果是一片白啊一片白。经查,发现是安全中心中的“悬浮窗”权限并没有对我们的这个新app开放,那么将权限开放,重启app,啊呀,一片红啊一片红。。。长按物理菜单键或者死命摇一摇手机,会弹出一个小窗口,选择“Dev Settings”,然后选择“Debug server host for device”,会弹出一个输入框,输入电脑ip地址和默认的8081端口,再次重新app,啊呀,粗线了粗线了。。。
但是由于npm上的版本在windows下存在BUG,因此需要安装github上的master支线,否则会在下一步骤报以下错误:
This will walk you through creating a new React Native project in *** events.js:141 throw er; // Unhandled 'error' event ^ Error: spawn npm ENOENT at exports._errnoException (util.js:837:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32) at onErrorNT (internal/child_process.js:344:16) at doNTCallback2 (node.js:429:9) at process._tickCallback (node.js:343:17) at Function.Module.runMain (module.js:477:11) at startup (node.js:117:18) at node.js:951:3
如果您看到本文时0.12已经发布,那很可能直接输入上面的命令就行了。如果0.12还没有发布,请进行以下步骤:
在React Native的Github页面右侧点击Download ZIP,下载后解压,并执行以下代码: