我是靠谱客的博主 阔达鱼,最近开发中收集的这篇文章主要介绍React Native Mac 环境搭建,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

打开终端:

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 环境搭建所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部