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_ONLYbuild 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
相关产品推荐
相关产品推荐

