ReactNative MacOS环境初始化项目

环境:macos 11.0.1

1. nrm use taobao
2. 安装Homebrew、XCode(Command Line Tools)
3. brew install watchman
4. brew install cocoapods
5. npx react-native init AwesomeProject
6. yarn install、cd ios && pod install

  • 问题:安装Homebrew异常
  • 解决:执行替代命令 /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

  • 问题:XCode配置
  • 解决:
    • 选择Command Line Tools
    • 下载模拟器ios系统(可选个最小的)

  • 问题:执行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.xmlREADME.md拷贝至mater文件夹
    • 在master文件夹执行git initgit 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

成功运行效果

参考文章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值