概述
打开终端:
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新的项目
启动模拟器
点击运行
最后
以上就是阔达鱼为你收集整理的React Native Mac 环境搭建的全部内容,希望文章能够帮你解决React Native Mac 环境搭建所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复