ReactNative MacOS环境初始化项目

环境:macos 11.0.1


  • 问题:安装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密钥,再新建一个config文件,内容如下
    Host github.com
    User [email protected](Github账号)
    Hostname ssh.github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    Port 443
    
    • 登录github,填入ssh密钥
    • 执行ssh -T [email protected],显示Hi xxx! You've successfully ...为配置成功
    • 重新执行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

成功运行效果

参考文章

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章