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

Mac M1初始化React Native项目遇JSON解析错误求助

React Native M1初始化CocoaPods JSON解析错误解决方案

问题概况

  • 设备:Macbook M1
  • 核心错误:CocoaPods安装依赖失败,抛出JSON::ParserError,无法解析/Users/mykytakhaliavkin/.cocoapods/repos/trunk/Specs/a/e/a/Flipper/0.232.0/Flipper.podspec.json,提示“unexpected token at ''”,同时附带“Framework build type is static library”警告。
  • 已尝试操作:brew安装/重装、清理缓存、重装macOS、执行rm -rf ~/.cocoapods/repos/trunk/

当前Podfile post_install配置

post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

解决步骤

1. 修复损坏的Flipper Spec文件

  • 删除本地损坏的Flipper版本目录:
    rm -rf ~/.cocoapods/repos/trunk/Specs/a/e/a/Flipper/0.232.0/
    
  • 重新拉取完整的Spec仓库:
    pod repo update trunk
    

2. 修正Podfile语法错误

原配置存在多余的end,导致语法异常,修正后代码:

post_install do |installer|
  # React Native官方post_install配置
  react_native_post_install(
    installer,
    config[:reactNativePath],
    :mac_catalyst_enabled => false
  )
  __apply_Xcode_12_5_M1_post_install_workaround(installer)
end

3. 添加静态库兼容配置

针对“Framework build type is static library”提示,在post_install中加入静态库适配代码:

post_install do |installer|
  react_native_post_install(
    installer,
    config[:reactNativePath],
    :mac_catalyst_enabled => false
  )
  __apply_Xcode_12_5_M1_post_install_workaround(installer)

  # 处理Flipper静态库构建问题
  installer.pods_project.targets.each do |target|
    if target.name == "Flipper"
      target.build_configurations.each do |config|
        config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
        config.build_settings['MACH_O_TYPE'] = 'staticlib'
      end
    end
  end
end

4. 锁定Flipper稳定版本

避开有问题的0.232.0版本,在Podfile中指定一个稳定版本:

use_flipper!({ 'Flipper' => '0.222.0' })

之后执行:

pod install --repo-update

5. M1架构适配

  • 用Rosetta打开终端:右键终端→显示简介→勾选“使用Rosetta打开”,再执行pod命令。
  • 或者强制以x86架构运行CocoaPods:
    arch -x86_64 pod install
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 22:30:06