2

I am getting two builds of the same codebase delivered as two separate frameworks: one for iOS device and one for simulator

Is there a way to conditionally include one or the other depending on the target of my app?

user3612643
  • 5,096
  • 7
  • 34
  • 55
  • Create a fat library by combining both the frameworks. Refer this thread https://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4 – Shantanu Sep 03 '19 at 05:07
  • That’s also what googling revealed: copy everything into one folder, but use lipo for all the binaries (main and dylibs). – user3612643 Sep 03 '19 at 05:08

2 Answers2

0

You can write script phase to replace framework file with some conditional( maybe is target architecture).

Thanh Vu
  • 1,599
  • 10
  • 14
0

Here is the solution. Assume the frameworks for iOS device and simulator are at folders $device resp. $simulator. The merged framework will go into $merged:

  • Copy everything from $simulator into $merged
  • Copy everything from $device into $merged (for sure this will overwrite same-named binaries we copied in the step before, but we just want to make sure we have everything else (module mappings etc.); the actual merging of same-named binaries happens in the next step)
  • For each binary (main and *.dylib) with name $name that exists both in $simulator and $device, do: lipo -create $device/name $simulator/$name -output $merged/$name

The above can easily be automated with a script.

I verified the approach with a set of frameworks we use with Flutter and it works. The easiest way is to add the $merged folder as a vendored framework into the podspec file

user3612643
  • 5,096
  • 7
  • 34
  • 55