ReactNative MacOS环境初始化项目(IOS)

环境: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

成功运行效果

其他问题


  • 问题:pod install 的libwebp(1.1.0)下载提示443
  • 解决:
    1. 打开~/.cocoapods/repos/trunk/Specs/1/9/2/libwebp/1.1.0/libwebp.podspec.json (trunk源)
    2. 修改如下两项地址
      "homepage": "https://github.com/webmproject/",
      ......
      "source": {
        "git": "https://github.com/webmproject/libwebp.git",
        "tag": "v1.1.0"
      },
    
    1. 同样的方式修改 ~/.cocoapods/repos/master/Specs/1/9/2/libwebp/1.1.0/libwebp.podspec.json (git源下载下来的master)
    2. 回到项目,重新 pod install --verbose --no-repo-update 安装成功

  • 问题:运行brew install cocoapods 时提示 Command failed with exit 128: git
  • 解决:按提示运行 git config --global --add ......

  • 问题:运行brew install cocoapods 时提示提示 Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP
  • 解决:
    1. 执行export HOMEBREW_NO_INSTALL_CLEANUP=TRUE
    2. 执行brew reinstall cocoapods


参考文章

posted @ 2022-02-20 13:26  KevinTseng  阅读(171)  评论(0编辑  收藏  举报