iosflutterxcodepodspec

How to conditionally load Frameworks based on target (device or simulator) in a CocoaPod spec?


I'm working on a CocoaPods spec file for an iOS project, and I need to include different vendored frameworks depending on whether the build is targeting a physical device or the simulator.

For example, I want to load:

Here's my current Podspec:

Pod::Spec.new do |s|
  s.name             = 'my_plugin'
  s.version          = '0.0.1'
  s.summary          = 'A new Flutter plugin project.'
  s.description      = 'A new Flutter plugin project.'
  s.homepage         = 'http://example.com'
  s.license          = { :file => '../LICENSE' }
  s.author           = { 'Your Company' => 'email@example.com' }
  s.source           = { :path => '.' }
  s.source_files     = 'Classes/**/*'
  s.dependency       'Flutter'
  s.platform         = :ios, '12.0'

  # Exclude i386 for simulator builds
  s.pod_target_xcconfig = {
    'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386'
  }
  s.swift_version = '5.0'

  # Include vendored frameworks
  s.vendored_frameworks = [
    'Frameworks/Demo.framework',
    'Frameworks-Simulator/Demo.framework'
  ]
end

Currently, both frameworks are included, but this causes issues during the build process as both frameworks are not compatible with all architectures. "Building for 'iOS-simulator', but linking in object file built for 'iOS'"

Is there a way to conditionally include one framework or the other based on whether the target is a physical device or a simulator?


Solution

  • The moment any .framework is added to a pod, it will be added to the binary, any added framework must have the appropriate architecture for the target build. The solution would be to ask the vendor for an xcframework or create one from these