React Native 开发环境准备

一、环境版本

macOS: 10.14.6

环境/IDE版本
node14.1
pod1.9.1
react-native0.62
Xcode11.3
IntelliJ IDEA2020.1

二、brew 环境配置

设置国内源

cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

三、node 环境配置

安装 node

brew install node

设置 npm 镜像

npx nrm use taobao

安装 yarn

npm install -g yarn

删除 react-native-cli

npm uninstall -g react-native-cli

四、CocoaPods 环境配置

安装 CocoaPods

brew install cocoapods

CocoaPods 镜像设置

cd ~/.cocoapods/repos 
pod repo remove trunk
pod repo remove master
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
在 Podfile 文件第一行添加:
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

设置 shell 代理

export all_proxy="http://127.0.0.1:8888"

五、hosts 设置

raw.githubusercontent.com 和 api.github.com 的 dns 可能不正确,可在 /etc/hosts 增加以下记录

151.101.108.133 raw.githubusercontent.com
13.250.94.254 api.github.com 

六、Xcode 环境问题

xcrun: error: SDK “iphoneos” cannot be located

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/

参考文档: