mac m1 react native iOS环境搭建跳坑

此文档虽然说是m1上搭建的,但是感觉应该同样适用于不是m1芯片的Mac
第一步:首先官方文档给出的是先安装Homebrew这个东西,如果你是Mac的老用户那么你知道这个是干啥的,但是很多像我一样Mac的新用户可能就不知道这个是什么鬼,其实这个就和node的功能一样,node提供一个npm,homebrew提供一个brew都是用来安装其他的包的一个工具;这个我早就装好了的;
第二步:
参考: Mac M1 搭建 React Native 环境
访达>应用程序>实用工具>右键 终端.app 显示简介>使用Rosetta打开勾选(我的是iterm)
Xcode的 Rosetta 也打开

第三步:

brew install node
brew install watchman

安装node我电脑上面是之前装好的,nvm,
我来说下watchman的坑
在安装watchman的时候会报错各种包资源下载404,然后让install包的时候就报错:在本地没有那个包的资源,具体的报错信息在iterm上被新的安装打印给顶掉了,看不到了
其中有一个:

curl: (22) The requested URL returned error: 404
......
tar: Error opening archive: Failed to open

类似于这个的包报错有很多,这个居然还不爆红,直到下面走到安装的时候才爆红
这个时候的话就要运行以下命令去解决(更新brew)

brew update

然后再一次运行

brew install watchman

这个时候应该就好了

第四步:
安装Command Line Tools,网上随便搜一下很多方法

xcode-select --install

第五步:
在这里插入图片描述
在这里插入图片描述
但是要怎么找这个东西呢?官方永远都是不清不楚…
看下面!!!!!!!!
打开安装好的Xcode,点击电脑左上角的Xcode
在这里插入图片描述
这里才会找到这个,大无语…

在这里插入图片描述
第六步:

brew install cocoapods

第七步创建项目:

npx react-native init AwesomeProject

报错:

✖ Installing CocoaPods dependencies (this may take a few minutes)
✖ Installing CocoaPods dependencies (this may take a few minutes)
error Error: Failed to install CocoaPods dependencies for iOS project, which is required by this template.
Please try again manually: "cd ./AwesomeProject/ios && pod install".
CocoaPods documentation: https://cocoapods.org/

根据提示到对应目录执行:

xxxxxxxxxxMacBook-Air ios % pod install

报错(网路太慢的原因):

[!] Error installing Flipper-Boost-iOSX
[!] /opt/homebrew/bin/git clone https://github.com/priteshrnandgaonkar/Flipper-Boost-iOSX.git /var/folders/3w/m12tvrsn1675q0_7x5plyglc0000gn/T/d20211201-24169-491zod --template= --single-branch --depth 1 --branch 1.76.0.1.11

正克隆到 '/var/folders/3w/m12tvrsn1675q0_7x5plyglc0000gn/T/d20211201-24169-491zod'...
fatal: 无法访问 'https://github.com/priteshrnandgaonkar/Flipper-Boost-iOSX.git/':LibreSSL SSL_connect: Operation timed out in connection to github.com:443

继续执行(如果有VPN可以直接VPN,否则还是接着执行这个命令):

xxxxxxxxxxMacBook-Air ios % pod install

继续报错:

[!] Error installing Flipper-Boost-iOSX
[!] /opt/homebrew/bin/git clone https://github.com/priteshrnandgaonkar/Flipper-Boost-iOSX.git /var/folders/3w/m12tvrsn1675q0_7x5plyglc0000gn/T/d20211201-24318-zmu57x --template= --single-branch --depth 1 --branch 1.76.0.1.11

正克隆到 '/var/folders/3w/m12tvrsn1675q0_7x5plyglc0000gn/T/d20211201-24318-zmu57x'...
fatal: 无法访问 'https://github.com/priteshrnandgaonkar/Flipper-Boost-iOSX.git/':LibreSSL SSL_read: Operation timed out, errno 60

继续执行:

xxxxxxxxxxMacBook-Air ios % pod install

就这样一直报错一直执行直至自己的包全部下载完成

最后用vs code打开项目,在终端输入以下命令,运行启动项目

npm run ios

这个时候呢会报错,因为这个东西不是用vs code去打开的,要用Xcode
注意:
在这里插入图片描述
这里的意思是要你用Xcode打开那个文件,在iOS目录下面呢
打开后最后一步:
在这里插入图片描述
点这个运行
然后就等着编译完成就好
完成后长这样:
在这里插入图片描述
到此Mac react native iOS可以正常开发了

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值