You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac M2设备React Native项目glog Pod安装失败求助

在M2 MacBook Pro上React Native项目pod install失败(glog安装报错)

问题详情

两周前购入MacBook Pro M2,此前在M1设备上使用React Native一年无问题。现在执行cd ios && pod install命令时,总会在安装glog Pod环节报错,无法正常运行npm run ios启动iOS模拟器。过去2-3周已重装Node、Ruby、Bundler、Xcode、Command Line Tools等所有相关工具,试过GitHub和Stack Overflow上的各种方案均无效。

报错信息

执行命令

cd ios && pod install

错误摘要

-> Installing boost (1.76.0)
  > Copying boost from
  `/Users/jvegax/Library/Caches/CocoaPods/Pods/External/boost/909665deed38b6f25051fac8c534aa3c-57d28` to `Pods/boost`

-> Installing fmt (6.2.1)
  > Copying fmt from `/Users/jvegax/Library/Caches/CocoaPods/Pods/Release/fmt/6.2.1-ff9d5` to `Pods/fmt`

-> Installing glog (0.3.5)
 > Git download
 > Git download
     $ /opt/homebrew/bin/git clone https://github.com/google/glog.git
     /var/folders/tn/v1qdr5nj7g75l5fj9qzx9px80000gn/T/d20230702-30759-hefom7 --template= --single-branch --depth 1
     --branch v0.3.5
Cloning into '/var/folders/tn/v1qdr5nj7g75l5fj9qzx9px80000gn/T/d20230702-30759-hefom7'...
Note: switching to 'a6a166db069520dbbd653c97c2e5b12e08a8bb26'.

You are in a 'detached HEAD' state. You can look around, make experimental changes and commits, and you can discard any commits you make in this state without impacting any branch by performing another checkout.

If you want to create a new branch to retain commits you create, you can do so (now or later) with the checkout command using -c. For example:

   git switch -c <new-branch-name>

Or undo the operation with:

   git switch -

Turn off this advice by setting the advice.detachedHead configuration variable to false.


[!] Error installing glog
  CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update

环境信息

React Native环境

System:
  OS: macOS 13.4.1
  CPU: (8) arm64 Apple M2
  Memory: 95.67 MB / 8.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.16.1
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 9.6.7
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2023.06.26.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /Users/jvegax/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.2 AI-222.4459.24.2221.10121639
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.19
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/jvegax/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

~/.zprofile配置

eval "$(/opt/homebrew/bin/brew shellenv)"

export ANDROID_SDK_ROOT="/Users/jvegax/Library/Android/sdk"
export ANDROID_PLATFORM_TOOLS="$ANDROID_SDK_ROOT/platform-tools"
export ANDROID_TOOLS="$ANDROID_SDK_ROOT/tools"
export ANDROID_TOOLS_BIN="$ANDROID_TOOLS/bin"
export ANDROID_BUILD_TOOLS="$ANDROID_SDK_ROOT/build-tools/33.0.0" #edit according to sdk version

path=(
  $ANDROID_TOOLS
  $ANDROID_SDK_ROOT
  $ANDROID_TOOLS_BIN
  $ANDROID_PLATFORM_TOOLS
  $ANDROID_BUILD_TOOLS
  $path
)

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
eval "$(rbenv init -)"

~/.zshrc配置

eval "$(/opt/homebrew/bin/brew shellenv)"

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

ZSH_THEME="gozilla"

source $ZSH/oh-my-zsh.sh

export ANDROID_SDK_ROOT="/Users/jvegax/Library/Android/sdk"
export ANDROID_PLATFORM_TOOLS="$ANDROID_SDK_ROOT/platform-tools"
export ANDROID_TOOLS="$ANDROID_SDK_ROOT/tools"
export ANDROID_TOOLS_BIN="$ANDROID_TOOLS/bin"
export ANDROID_BUILD_TOOLS="$ANDROID_SDK_ROOT/build-tools/33.0.0" #edit according to sdk version

path=(
  $ANDROID_TOOLS
  $ANDROID_SDK_ROOT
  $ANDROID_TOOLS_BIN
  $ANDROID_PLATFORM_TOOLS
  $ANDROID_BUILD_TOOLS
  $path
)

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
eval "$(rbenv init -)"

解决方案

1. 清理CocoaPods缓存并更新trunk

依次执行以下命令:

# 清理所有Pod缓存
pod cache clean --all
# 删除本地缓存目录
rm -rf ~/Library/Caches/CocoaPods
# 删除项目中的Pod相关文件
rm -rf ios/Pods
rm -rf ios/Podfile.lock
# 更新CocoaPods trunk仓库
pod repo update trunk
# 重新安装Pods
cd ios && pod install

2. 替换glog源或指定版本

在项目的ios/Podfile中添加或修改glog的配置,使用国内镜像加速或指定兼容版本:

# 使用GitHub官方源指定版本
pod 'glog', :git => 'https://github.com/google/glog.git', :tag => 'v0.3.5'
# 或者使用国内镜像
pod 'glog', :git => 'https://gitee.com/mirrors/glog.git', :tag => 'v0.3.5'

修改后重新执行cd ios && pod install。

3. 用Rosetta模式运行终端

M2芯片可能存在架构兼容问题,开启终端的Rosetta模式:

  • 找到Launchpad「其他」文件夹中的「终端」应用
  • 右键点击终端,选择「显示简介」
  • 勾选「使用Rosetta打开」
  • 重启终端后重新执行pod install

4. 升级CocoaPods版本

当前使用的CocoaPods 1.12.1可能存在M2兼容问题,升级到最新稳定版:

gem install cocoapods

升级完成后重新执行cd ios && pod install。

5. 检查Xcode命令行工具路径

确保Xcode命令行工具路径正确:

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

执行后重新运行pod install。

内容的提问来源于stack exchange,提问作者jvegax

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 23:55:02