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

React Native 0.71.3 iOS包装框架私有Podspec创建失败求助

问题描述

背景

我正尝试将React Native 0.71.3应用的iOS包装框架制作为Cocoapod,用于分发给第三方用户,该框架需作为桥接层,在接收订阅者应用触发信号时启动React Native应用。但由于对Cocoapods用法了解有限,遇到了无法解决的问题。

Podfile内容

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, min_ios_version_supported
prepare_react_native_project!

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'BareSdk' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    # Upcoming versions of React Native may rely on get_default_flags(), but
    # we make it explicit here to aid in the React Native upgrade process.
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'BareSdkTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    react_native_post_install(
      installer,
      # Set `mac_catalyst_enabled` to `true` in order to apply patches
      # necessary for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

Podspec内容

react_native_version = "0.71.3"

current_file_dir = File.dirname(__FILE__)

Pod::Spec.new do |s|
  s.name         = "My-SDK-POC"
  s.version      = "1.0"
  s.summary      = "My-SDK-POC"
  s.description  = "My-SDK-POC react native SDK"
  s.homepage     = "[私有仓库首页]"
  
  s.license      = "MIT"
  s.author       = { "John Smith" => "jsmith@gmail.com" }
  s.platform     = :ios, "14.0"
  s.source       =  { :git => '[私有仓库地址]' }
  s.source_files = "ios-sdk-poc/**/*.{swift,h,m,mm,cpp}"
  s.preserve_paths = "ios-sdk-poc/**/*"

  s.requires_arc = true
  s.swift_version= '5.0'

  Dir.each_child(File.join(current_file_dir, 'Pods/Local Podspecs')) do |podspec_name|
    podspec_split_name = podspec_name.split(/\./)
    s.dependency podspec_split_name[0]
  end
end

执行pod repo push ios-podspecs My-SDK-POC.podspec时的报错

错误信息

Testing with `xcodebuild`.
-> My-SDK-POC (1.0)
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.
...
    - NOTE  | [iOS] xcodebuild:  Headers/Public/hermes-engine/jsi/jsi.h:10:10: fatal error: 'cassert' file not found
    - NOTE  | [iOS] xcodebuild:  React-RCTText/Libraries/Text/VirtualText/RCTVirtualTextViewManager.m:8:9: fatal error: could not build module 'React'
[!] The `My-SDK-POC.podspec` specification does not validate.

警告信息

[!] Found multiple specifications for `glog (0.3.4)`:
- /Users/johnSmith/.cocoapods/repos/cocoapods/Specs/4/7/2/glog/0.3.4/glog.podspec.json
- /Users/johnSmith/.cocoapods/repos/trunk/Specs/4/7/2/glog/0.3.4/glog.podspec.json

[!] Found multiple specifications for `React (0.13.0-rc)`:
- /Users/johnSmith/.cocoapods/repos/cocoapods/Specs/5/0/c/React/0.13.0-rc/React.podspec.json
- /Users/johnSmith/.cocoapods/repos/trunk/Specs/5/0/c/React/0.13.0-rc/React.podspec.json
...

已尝试但无效的方法

  • 在Podspec中单独列出所有Pods作为依赖
  • 修改Xcode中的C/C++语言方言

解决方案

1. 修复Podspec的依赖引用逻辑

你当前通过遍历Pods/Local Podspecs目录添加依赖的方式不可靠,因为这个目录是本地pod install后的产物,在podspec校验时不存在,而且会引入不必要的旧版本依赖(比如旧版React)。正确的做法是直接声明React Native核心及相关依赖,并锁定版本:

修改Podspec的依赖部分为:

# 声明React Native核心依赖,锁定版本
s.dependency "React", react_native_version
s.dependency "React-Core", react_native_version
s.dependency "React-CoreModules", react_native_version
s.dependency "React-RCTText", react_native_version
s.dependency "hermes-engine", react_native_version
# 根据你的RN项目实际用到的模块添加,比如如果用到原生模块也需要声明
# s.dependency "React-RCTImage", react_native_version

同时删除原来的遍历目录添加依赖的代码块。

2. 解决多仓库依赖冲突警告

多个仓库存在相同版本的podspec是因为你的本地Cocoapods仓库中有重复源,比如同时添加了cocoapods和trunk源。可以通过以下步骤清理:

  • 执行pod repo list查看所有本地仓库
  • 删除重复的仓库,比如执行pod repo remove cocoapods(保留trunk作为官方源即可)
  • 之后执行pod repo update更新仓库索引

3. 配置正确的编译参数以解决cassert找不到的问题

cassert是C标准库头文件,需要确保你的Podspec中正确配置了C编译选项:

在Podspec中添加:

# 设置C++标准
s.xcconfig = {
  'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
  'CLANG_CXX_LIBRARY' => 'libc++'
}

4. 确保Podspec的source路径正确

当前Podspec的source指向的是远程仓库,但需要确保仓库中包含所有必要的文件(RN编译后的产物、你的桥接层代码等)。如果是本地测试,可以先使用:path来指向本地目录,验证通过后再切换到远程地址:

s.source = { :path => "." } # 本地测试用

5. 校验Podspec前先本地验证

在推送到私有仓库前,先执行本地校验命令,更易排查问题:

pod lib lint My-SDK-POC.podspec --verbose --allow-warnings

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 11:39:58