初始化React-Native项目,卡在Installing C
2020-12-15 本文已影响0人
iOS丶Michelle
准备工作
1.电脑 Mac
2.系统 macOS Big Sur
3.安装nodejs(建议选择稳定版,别太高)
4.安装nrm(方便你切换源)
npm install -g nrm
4-1 查看源列表
nrm ls
4-2添加源<registry> <url>,其中reigstry为源名,url为源的路径。
nrm add registry http://registry.npm.frp.trmap.cn/
4-3切换源,如果要切换到taobao源
nrm use taobao
4-4删除源执行命令nrm del <registry>删除对应的源。
5.安装CocoaPods(教程很多)
初始化React-Native项目
官网万能代码,AwesomeProject是项目名,你随意换
npx react-native init AwesomeProject
第一次装,卡在Installing CocoaPods Dependencies
不用等了,不会成功的,直接点X关闭
之前我们已经安装了CocoaPods,不需要再去删除又重新安装了
先确定gems镜像源
gem sources -l
如果你没换到国内的镜像源先添加
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
像这样就是ok了

pod repo 换源
查看
pod repo
切换到目录
cd ~/.cocoapods/repos
删除旧版的master或者是trunk,反正确保你当前只有一个源
pod repo remove master
克隆指定源(等一会,大概5~6分钟)
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
我是先git clone,然后再查看,然后再删除trunk

最后一步了
神秘代码
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
刚才我们不是初始化了一个React-Native项目嘛,然后用VS Code打开,然后找到Podfile文件,把神秘代码放到第一行

然后右击ios文件夹在终端打开
输入
pod install
等待一会

安装完成后,提示这样就算OK了:
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在终端打开
输入
yarn ios
等待大概12分钟这样吧,要有耐心
下一次新建项目不需要再修改Podfile文件了,
我又重新初始化一个项目RN01,速度明显提升了

很舒服
