1

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.

sandpat
  • 1,478
  • 12
  • 30

2 Answers2

2

Have you tried any of these :

1.Adding -ObjC in Build Settings -> Linking -> Other Linker Flags.

2.Importing all the frameworks that the Objective C framework depends on into your project i.e;in Build Phases --> Link Binary With Libraries .

3.Adding #import's for those to a prefix header file, which must be added to your project in build settings in the Prefix Header field.

Update : Elaborating point 3 :

To use Objective C Framework in your Swift project you have to create a Swift Bridging Header file in that project. The best way is to create the .h file Manually.

First, add a header file to your project with the name: MyProjectName-Bridging-Header.h. This will be the single header file where you import any Objective C code you need your Swift code to have access.

Find Swift Compiler - Code Generation section in your project build settings. Add the path to your bridging header file next to Objective C Bridging Header from the project root folder. It should be MyProject/MyProject-Bridging-Header.h

It just needs a single Bridging Header. Enter #import statements to this file and your classes will be available in your Swift project code without any additional #import statements.

build settings

You can also have a look at this tutorial : Integrating objective c in swift

Pooja Kamath
  • 1,290
  • 1
  • 10
  • 17
1

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.

sandpat
  • 1,478
  • 12
  • 30