【问题标题】:Build target MyNotificationService: Framework not found构建目标 MyNotificationService:找不到框架
【发布时间】:2021-10-14 23:24:41
【问题描述】:

我有一个 React Native 应用程序“MyApp”,它附加了一个“MyNotificationService”(即,NotificationService.appex 嵌入在目标“MyApp”中的 Frameworks, Libraries and Embedded Content in Xcode 下)。

到目前为止一切都很好。

现在我想在“MyApp”中添加另一个 pod,命名为 pod 'Google-Mobile-Ads-SDK',这与 MyNotificationService 没有任何关系。我只是想安装它,所以我可以访问“MyApp”中的Google-Mobile-Ads-SDK

我的 Podfile 看起来像这样

target 'MyApp' do
  
  use_unimodules!
  config = use_native_modules!
  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => false
  )

  # Additional Dependencies
  ...
  pod 'Google-Mobile-Ads-SDK'
 
  target 'MyNotificationService' do   
    use_native_modules!
    inherit! :complete
  end

  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
        # deletes each pods deployment target definition and instead uses the definition of the main project
        config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
      end
    end
  end
end

但是,在我运行 pod install 之后,我尝试使用 XCode 构建 MyApp 的调试版本,但 XCode 报错:

Build Target MyNotificationService
Link MyNotificationService (arm64)

Directory not found for option '-F/Users/.../Library/Developer/Xcode/DerivedData/MyApp-abcabcabcabcabc/Build/Products/Debug-iphoneos/XCFrameworkIntermediates/GoogleAppMeasurement'

Directory not found for option '-F/Users/.../Library/Developer/Xcode/DerivedData/MyApp-abcabcabcabcabc/Build/Products/Debug-iphoneos/XCFrameworkIntermediates/GoogleMobileAds'

Directory not found for option '-F/Users/.../Library/Developer/Xcode/DerivedData/MyApp-abcabcabcabcabc/Build/Products/Debug-iphoneos/XCFrameworkIntermediates/UserMessagingPlatform'

但 MyNotificationService 与 GoogleAppMeasurementGoogleMobileAdsUserMessagingPlatform 这些框架无关 - 它们属于 Google-Mobile-Ads-SDK,只有主要目标 MyApp 需要它们。

我如何告诉MyNotificationService 它不应该关心这些框架?

【问题讨论】:

    标签: ios xcode react-native cocoapods ios-app-extension


    【解决方案1】:

    确实使用抽象目标解决了问题,其中定义了“MyApp”和“MyNotificationService”作为子目标。抽象目标不是一个实际的 Xcode 目标,而是一个占位符或文件夹,它定义了“MyApp”和“MyNotificationService”都应该共享的 pod。要让“MyNotificationService”忽略与“Google-Mobile-Ads-SDK”相关的所有内容,pod 'Google-Mobile-Ads-SDK' 仅在子目标“MyApp”中定义。

    abstract_target 'Shared' do
      
      use_unimodules!
      config = use_native_modules!
      use_react_native!(
        :path => config[:reactNativePath],
        # to enable hermes on iOS, change `false` to `true` and then install pods
        :hermes_enabled => false
      )
    
      # Additional Dependencies
      ...
    
      target 'MyApp' do
        # no inherit statement means that target MyApp has all pods from the parent "Shared" accessible
        pod 'Google-Mobile-Ads-SDK'
      end
    
      target 'MyNotificationService' do 
          # no inherit statement means that target MyNotificationService has all pods from the parent "Shared" accessible
        use_native_modules!
      end
     
      post_install do |installer|
        installer.pods_project.targets.each do |target|
          target.build_configurations.each do |config|
            config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
            # deletes each pods deployment target definition and instead uses the definition of the main project
            config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
          end
        end
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2022-11-07
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 2016-04-16
      • 2017-03-29
      • 1970-01-01
      相关资源
      最近更新 更多