初始化React-Native项目,卡在Installing CocoaPods Dependencies

准备工作

1.电脑 Mac
2.系统 macOS Big Sur
3.安装nodejs(建议选择稳定版,别太高)
4.安装nrm(方便你切换源)

1
npm install -g nrm

4-1 查看源列表

1
nrm  ls

4-2添加源 ,其中reigstry为源名,url为源的路径。

1
nrm add registry http://registry.npm.frp.trmap.cn/

4-3切换源,如果要切换到taobao源

1
nrm use taobao

4-4删除源执行命令nrm del 删除对应的源。
5.安装CocoaPods(教程很多)

初始化React-Native项目

官网万能代码,AwesomeProject是项目名,你随意换

1
npx react-native init AwesomeProject

第一次装,卡在Installing CocoaPods Dependencies


不用等了,不会成功的,直接点X关闭

cocopds_dependencies好慢.png

之前我们已经安装了CocoaPods,不需要再去删除又重新安装了

先确定gems镜像源

1
gem sources -l

如果你没换到国内的镜像源先添加

1
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/

像这样就是ok了


gems镜像源.png

pod repo 换源

查看

1
pod repo

切换到目录

1
cd ~/.cocoapods/repos

删除旧版的master或者是trunk,反正确保你当前只有一个源

1
pod repo remove master

克隆指定源(等一会,大概5~6分钟)

1
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

我是先git clone,然后再查看,然后再删除trunk


保留一个repo.png

最后一步了

神秘代码

1
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

刚才我们不是初始化了一个React-Native项目嘛,然后用VS Code打开,然后找到Podfile文件,把神秘代码放到第一行


修改项目下Podfile文件.png

然后右击ios文件夹在终端打开
输入

1
pod install

等待一会


pod_install安装时间.png

安装完成后,提示这样就算OK了:

1
2
3
4
5
6
Generating Pods project
Integrating client project
 
[!] Please close any current Xcode sessions and use `firstApp.xcworkspace` for this project from now on.
Pod installation complete! There are 33 dependencies from the Podfile and 37 total pods installed.
appledeMacBook-Pro:ios apple$

运行React-Native项目在iOS模拟器

右击AwesomeProject在终端打开
输入

1
yarn ios

等待大概12分钟这样吧,要有耐心

下一次新建项目不需要再修改Podfile文件了,

我又重新初始化一个项目RN01,速度明显提升了


初始化RN01项目.png

很舒服


nice.png