Search code examples
objective-cswiftalamofiremoyadynamic-frameworks

Creating a fat framework with an objective c framework dependency


I am working with Swift 4.2 and Xcode 10.1. I am trying to build a framework in Swift that depends on Alamofire which is written in Objective C. I added the Alamofire.xcodeproj manually as given in the README by Alamofire. The individual target builds fine. My Framework target builds fine.

The problem arises when I try to create a fat framework using a script that uses the following command

xcodebuild -project "${FRAMEWORK_NAME}.xcodeproj" -scheme "${FRAMEWORK_NAME}" -configuration "${CONFIGURATION}" -arch arm64 -arch armv7 -arch armv7s only_active_arch=no BITCODE_GENERATION_MODE=bitcode defines_module=yes -sdk "iphoneos" -derivedDataPath "${OUTPUT_DIR}"

I get the following error:

umbrella header 'Alamofire.h' not found

could not build Objective-C module 'Alamofire'

The second line of the error is coming from another dependency 'Moya' that depends on Alamofire (See Image)
enter image description here

It's puzzling that normal Cmd+B works fine for usual target but xcodebuild fails.

Things that I attempted:

  1. Deleting Derived folder, Clean Build.
  2. Building individual dependencies first and then build the Universal Aggregated Target.
  3. Creating a custom module map
  4. Changing configurations of all dependencies to same e.g. Debug
  5. Changing Swift Language Version of Alamofire.xcodeproj to be Swift 4.2

I think xcodebuild command needs more input. What am I missing?

Updates:

I dig in further. The Headers folder inside Debug-iphoneos/Alamofire.framework/ is empty which it is expected to contain umbrella header Alamofire.h.


Solution

  • Turns out, the nested dependency was an issue.

    MyFramework had dependency on Moya and Moya had dependency on Alamofire. After I added Alamofire.xcodeproj as submodule to Moya.xcodeproj, xcodebuild magically found all umbrella headers correctly.