ReactNative MacOS环境初始化项目
环境:macos 11.0.1
- 官方教程 https://reactnative.cn/docs/environment-setup
- 问题:安装Homebrew异常
- 解决:执行替代命令
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
- 问题:XCode配置
- 解决:
- 选择Command Line Tools
- 下载模拟器ios系统(可选个最小的)
- 选择Command Line Tools
- 问题:执行
brew install cocoapods
提示github连接443 - 解决:
- 检查修改本地git配置为正确的github账号(user.name 和 user.email)
- 删除
~/.ssh
目录下所有文件,重新生成ssh密钥,
git config --global user.name "xxx(Github账号)" git config --global user.email "xxx@qq.com(Github账号)" git config --global credential.helper.store ssh-keygen -t rsa -C "xxx@qq.com" cat ~/.ssh/id_rsa.pub open ~/.ssh
- 再新建一个
config
文件,内容如下
Host github.com User xxxxxxx@qq.com(Github账号) Hostname ssh.github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Port 443
- 登录github,填入ssh密钥
- 执行
ssh -T git@github.com
,显示Hi xxx! You've successfully ...
为配置成功 - 延长超时时间
git config --global http.lowSpeedLimit 1000 git config --global http.lowSpeedTime 1800000
- 重新执行
brew install cocoapods
- 问题:执行
npx react-native init AwesomeProject
安装依赖时失败,提示可以在项目ios目录中手工执行pod install
。但手工执行失败,都提示github 443超时错误。 - 解决:手工下载依赖包
- 打开
https://github.com/CocoaPods/Specs
下载zip包,然后解压缩 - 打开
~/.cocoapods/repos
文件夹,新建master
文件夹 - 将解压后的文件夹
Specs
和文件CocoaPods-version.xml
、README.md
拷贝至mater
文件夹 - 在master文件夹执行
git init
和git remote add origin https://github.com/CocoaPods/Specs
- 重新在项目的ios文件夹执行
pod install --verbose --no-repo-update
(可尝试配合以下命令设置代理)
git config --global http.proxy "127.0.0.1:1080" git config --global https.proxy "127.0.0.1:1080"
- 执行完后再清除代理
git config --global http.proxy "" git config --global https.proxy ""
- 期间最后会有几个包还需要下载,如果提示443,多试几次
pod install
,直到所有包下载完
- 打开
- 问题:
yarn ios
编译提示Build Commands Failed: PhaseScriptExecution...
- 解决:
- 删除重新安装yarn
brew uninstall --force yarn npm r -g yarn brew install yarn brew link yarn yarn -v
- 重新执行后成功
- 问题:运行成功打开ios模拟器后提示
No bundle URL present
- 解决:安装switchhosts,配置host映射
127.0.0.1 localhost
成功运行效果
参考文章
- https://zhuanlan.zhihu.com/p/111014448