Alamofire: WATCHOS_DEPLOYMENT_TARGET less than 6.0 is not compiled if Alamofire is installed via Swift Packages

Created on 15 Jul 2020  ·  13Comments  ·  Source: Alamofire/Alamofire

What did you do?

  1. Create new project iOS App with Watch App (WATCHOS_DEPLOYMENT_TARGET is 6.2 by default)
  2. Integrate Alamofire to WatchKit Extension via Swift Packages (it was built successfully)
  3. Set WATCHOS_DEPLOYMENT_TARGET for example to 5.0

What did you expect to happen?

I expect that it should be built successfully as declared watchOS 3.0+

What happened instead?

Linker error:
Undefined symbol: _OBJC_CLASS_$_NSURLSessionTaskMetrics

Alamofire Environment

Alamofire version: 5.2.1
Xcode version: 11.5
Swift version: 5.1
Platform(s) running Alamofire: watchOS
macOS version running Xcode: 10.15.5

Demo Project

TestAlamofire.zip

needs investigation

All 13 comments

Hmm, some Apple platforms do require CFNetwork to be linked in order to properly find some symbols. For now you should try adding an explicit linking of CFNetwork to your project and I'll see how we can replicate that using SPM.

@maxx-cyber Yes, looks like adding an explicit linker statement fixes the issue. You can try the bug/spm-explicit-cfnetwork-linking branch for now until I get a PR up and merged.

This fix was released as part of Alamofire 5.2.2.

Hi @jshier
This issue is still reproduced under Xcode 12 beta 2 even after fix :)

@maxx-cyber Bizarrely, the issue still exists even after updating the package in Xcode to 5.2.2. However, removing and adding the package again at the exact same version works fine. I'll report it as an SPM in Xcode bug.

@jshier Updating package to 5.2.2 under Xcode 11.6 works fine for me without removing and adding the package. But under Xcode 12 beta 2 it doesn't work at all, even after removing and adding the package, even after removing DerivedData folder.

@jshier Just try it

Your sample project works fine for me after removing and adding the package in Xcode 12b2. This seems to be a bug in Xcode's SPM integration, which I've filed as FB8080727.

I've removed ~/Library/Develop folder, reboot mac, created absolutely new sample project under Xcode 12b2, decreased watchOS deployment target to 5.0 (it requires to comment some code to be compilable), added Alamofire swift package and all this doesn't help. I have macOS 10.15.5, did you update it to 10.15.6?

I am on 10.15.6, but it's unlikely that makes a difference here, since Xcode's SPM functionality is self contained. I've confirmed again that removing Alamofire and adding again lets the build work.

Actually, it looks like adding the framework again doesn't add it to any targets, but the build still works. Adding it to the watch extension does break the build in general. You can manually work around the linking error by adding -framework CFNetwork to the "Other Linker Flags" setting on your extension target.

Yes, -framework CFNetwork works 👍
May be it will be nice to add this to installation instruction.

It's only necessary due to Xcode 12 ignoring the setting from the package. Hopefully they just fix the bug.

Was this page helpful?
0 / 5 - 0 ratings