You need to enable JavaScript to run this app. iOS 12.5环境下React Native共享扩展编译失败如何解决
优惠活动
大模型
产品
解决方案
定价
更多

iOS 12.5环境下React Native共享扩展编译失败如何解决

iOS 12.5编译APPLICATION_EXTENSION_API_ONLY报错解决方案

报错原文:Application extensions and any libraries they link to must be built with the APPLICATION_EXTENSION_API_ONLY build setting set to YES.

当前全局修改所有Pod目标配置的方式是冲突根源:苹果要求App Extension关联的所有依赖必须开启APPLICATION_EXTENSION_API_ONLY配置,而你为了解决RN的已知问题全局关闭了该配置,才会触发扩展编译报错。

解决步骤

  • 不要全局修改所有target的配置,区分普通App目标和Extension对应的Pod目标,仅关闭非Extension关联依赖的配置。修改你的Podfile post_install代码如下:
post_install do |installer|
  # 替换成你项目中实际的Extension target名称,比如TodayExtension、ShareExtension等
  extension_targets = ['你的Extension目标名']
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      # 仅非Extension关联的依赖设置为NO
      unless extension_targets.any? { |ext| target.name.include?(ext) }
        config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
      end
    end
  end
end
  • 执行命令清除旧配置并重新安装依赖:
pod deintegrate && pod install
  • 检查主项目中Extension target自身的Build Settings,确认APPLICATION_EXTENSION_API_ONLY配置为YES,未被其他配置覆盖。
  • 如果仍有报错,排查用到的第三方库是否在Extension中调用了苹果禁止Extension使用的API,比如UIApplication的相关方法,RN项目还需确认原生模块没有在Extension侧调用不可用API。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.21 13:45:04