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

添加NotificationServiceExtension Target为何导致iOS构建阶段循环错误?

iOS构建循环错误解决方案(添加Notifee远程通知支持时)

问题描述

按照Notifee的iOS远程通知支持文档配置,通过Xcode添加了NotificationServiceExtension目标,并在Podfile中添加了以下配置:

$NotifeeExtension = true  
target 'NotifeeNotificationService' do   
    pod 'RNNotifeeCore', :path => '../node_modules/@notifee/react-native/RNNotifeeCore.podspec' 
end

安装Pods成功后,构建项目时出现循环依赖错误,错误核心信息:

Cycle inside MyTarget; building could produce unreliable results.
Cycle details:
→ Target 'MyTarget': CodeSign ...
○ That command depends on command in Target 'MyTarget': script phase “[CP] Embed Pods Frameworks”
○ That command depends on command in Target 'MyTarget': script phase “[CP-User] [RNFB] Core Configuration”
○ Target 'MyTarget' has process command with output '.../MyTarget.app/Info.plist'
○ Target 'MyTarget' has copy command from '.../NotifeeNotificationService.appex' to '.../MyTarget.app/PlugIns/NotifeeNotificationService.appex'

完整Podfile内容如下:

# Resolve react_native_pods.rb with node to allow for hoisting

require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"react-native/scripts/react_native_pods.rb",
{paths: [process.argv[1]]},
)', __dir__]).strip

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.disabled
use_frameworks! :linkage => :static
$RNFirebaseAsStaticFramework = true

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 'MyTarget' 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.
: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 'MyTargetTests' do
inherit! :complete # Pods for testing
end
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)
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
end
end
end
end

$NotifeeExtension = true
target 'NotifeeNotificationService' do
pod 'RNNotifeeCore', :path => '../node_modules/@notifee/react-native/RNNotifeeCore.podspec'
end

解决方案

循环错误的核心原因是Podfile中全局设置了APPLICATION_EXTENSION_API_ONLY = NO,而Notification Service Extension本身需要开启APPLICATION_EXTENSION_API_ONLY = YES,两者的依赖关系因此产生循环。

按照以下步骤修改:

  1. 修改Podfile的post_install部分
    移除全局设置APPLICATION_EXTENSION_API_ONLY = NO,改为只给主App目标(和测试目标)设置,排除Extension目标:

    post_install do |installer| 
      react_native_post_install(
        installer,
        config[:reactNativePath],
        :mac_catalyst_enabled => false
      )
      __apply_Xcode_12_5_M1_post_install_workaround(installer)
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
          # 只给非Extension的目标关闭APPLICATION_EXTENSION_API_ONLY
          unless target.name == 'NotifeeNotificationService' || target.name.start_with?('Pods-NotifeeNotificationService')
            config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
          end
        end
      end
    end
    
  2. 检查Extension目标的Build Settings
    在Xcode中选中NotifeeNotificationService目标,进入Build Settings,确保APPLICATION_EXTENSION_API_ONLY设置为YES(默认应该是开启的,但需要确认)。

  3. 重新安装Pods并清理构建缓存
    执行以下命令:

    cd ios
    pod deintegrate
    pod install
    rm -rf ~/Library/Developer/Xcode/DerivedData
    
  4. 调整构建阶段顺序(如果仍有问题)
    如果循环错误依然存在,进入主App目标的Build Phases,将[CP-User] [RNFB] Core Configuration脚本阶段移动到[CP] Embed Pods Frameworks之前。

这样修改后,主App和Extension的构建依赖关系会恢复正常,循环错误即可解决。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 20:27:02