React Native Mac 环境搭建

来源:互联网 发布:java实现扫码支付 编辑:程序博客网 时间:2024/05/20 05:05

打开终端:

brew install node

看到

这里写图片描述

输入npm -v 后查看安装成功的node.js

然后执行
npm install -g react-native-cli

安装react-native 命令行工具

react-native –help

可以查看命令行工具支持的命令

接下来安装Xcode
之后安装Android Studio

然后初始化一个应用

react-native init FirstApp

如果收到-bash:react-native:command not found

则输入
npm list -g | head -n 1
得到
/usr/local/Cellar/node/8.1.4/lib
得到react native 安装的路径

open .bash_profile
添加
export PATH=”/usr/local/Cellar/node/8.1.4/bin:$PATH”

source .bash_profile

再次执行

react-native init FirstApp

则看到成功创建第一个apk

用命令后运行iOS项目

cd FirstApp
执行
react-native run-ios

如果遇到错误:
xcrun: error: unable to find utility “instruments”, not a developer tool or in PATH
则要执行
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
再次运行遇到错误:

Installing build/Build/Products/Debug-iphonesimulator/MyFirsrRNapp.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, “:CFBundleIdentifier”, Does Not Exist

Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/MyFirsrRNapp.app/Info.plist
Print: Entry, “:CFBundleIdentifier”, Does Not Exist

修改方法:
react-native 中文参考网有解释:
http://reactnative.cn/docs/0.49/getting-started.html#content

http://blog.csdn.net/s8460049/article/details/73330784

首先要启动一个android模拟器
react-native run-android

分别运行俩个平台的项目

要安装好各自的模拟器

可以通过Xcode 运行iOS项目,双击
FirstApp.xcodeproj
点击运行按钮
通过a s 运行android项目,open新的项目
启动模拟器
点击运行

原创粉丝点击