Facebook-ios-sdk: Swift dependencies in Xcode for Static framework SDK 7.1.1

Created on 12 Aug 2020  路  10Comments  路  Source: facebook/facebook-ios-sdk

Checklist

Environment

Describe your dev environment here, giving as many details as possible. If you have them, make sure to include:

  • Xcode Version: 11.6
  • Installation Platform & Verison: [Manual] version 7.1.1
  • iOS app Developed in C++ and Objective C

Goals

What do you want to achieve?
Update the app with the latest Static FB SDK

Expected Results

What do you expect to happen?
No compilation error

Actual Results

What actually happened? Can you provide a stack trace?

Compilation error is observed
[See attachment for log]
[log.txt](https://github.com/facebook/facebook-ios-sdk/files/5062828/log.txt)
errors.txt

Steps to Reproduce

What are the steps necessary to reproduce this issue?

  1. Replaced the old SDK framework with the new SDK (static framework)
  2. Generate a build
  3. Compilation error is observed

Code Samples & Details

Is there a way to remove the swift dependencies?
Why is it required for my app build with C++ and Obj C?

I have tried removing the swift dependencies issue but the enterprise build is crashing for iPhone/iPad with iOS 11 and less with the following error:

Termination Description: DYLD, Library not loaded: @rpath/libswiftCore.dylib | Referenced from: /var/containers/Bundle/Application/40FD2ADF-D720-41F6-8AA8-EF4A27F2320A/Example.app/Example | Reason: no suitable image found. Did find: | /private/var/containers/Bundle/Application/40FD2ADF-D720-41F6-8AA8-EF4A27F2320A/Example.app/Frameworks/libswiftCore.dylib: code signature invalid for '/private/var/containers/Bundle/Application/40FD2ADF-D720-41F6-8AA8-EF4A27F2320A/Example.app/Frameworks/libswiftCore.dylib'

All 10 comments

I'm guessing this might be a project settings issue... are you able to reproduce this with a new sample project that you can link to?

I'm seconding this request. Starting with 7.x versions, no ObjC-only (default) SDKs are supplied, only ones linking easing Swift interfaces. 6.x versions used to be distributed ObjC-only by default; builds for Swift users containing Swift stubs were marked with -Swift in the archive name.

I'm seconding this request. Starting with 7.x versions, no ObjC-only (default) SDKs are supplied, only ones linking easing Swift interfaces. 6.x versions used to be distributed ObjC-only by default; builds for Swift users containing Swift stubs were marked with -Swift in the archive name.

There are other issues in this repo that litigate the Swift vs ObjC-only debate. I'd prefer to keep the focus here on helping address issues with upgrading. To that end a sample project reproducing the issue would help a lot. Thanks!

Archive.zip

Here's a sample app duplicated in two folders 鈥撀爋ne linking Facebook SDKs v6.x which _compiles successfully_, the other linking SDKs v7.x wich FAILS to compile, both using CocoaPods (so pod install is needed in this particular example).

TL;DR:

  • Swift-specific SDKs (with -Swift in archive name) are not distributed separately any more
  • Static frameworks (and probably all the others) are distributed with Swift shims force-linked
  • Including Facebook SDKs using CocoaPods cannot be used as a workaround as these fail to compile as well due to missing Swift runtime linking

@username0x0a - there are a few ways to get this compiling.

Easiest way is to add the argument use_frameworks! to your Podfile.

Second way is to add an empty Swift file to the project. This will prompt Xcode to add the following to the linker command that gets run during the build:

-L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/joesusnick/Library/Developer/Xcode/DerivedData/SDKsTest-ggzibsmcvkvaoscguxraeabpjevp/Build/Intermediates.noindex/SDKsTest.build/Debug-iphonesimulator/SDKsTest.build/Objects-normal/x86_64/SDKsTest.swiftmodule

Third way is to add these arguments yourself in the build settings. They correspond to:

LIBRARY_SEARCH_PATHS: "$(inherited) ${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
OTHER_LDFLAGS: "$(inherited) -Xlinker -add_ast_path -L /usr/lib/swift"

Reference:
https://pewpewthespells.com/blog/buildsettings.html
https://blog.cpming.top/p/react-native-0-62-undefined-symbol

Yeah. I'd call these _workarounds_.

  • use_frameworks! solution is only usable in case one uses CocoaPods to integrate the SDK. Moreover, this forces generation of dynamic frameworks which cannot be dead-code-stripped (including the Swift code) and merged with main binary during linking. Anybody who used to integrate the FB-provided static binaries (me included 鈥撀爓ith automated download, architectures stripping, static linking with dead code stripping and tight linking with app binary) has no luck at this moment.
  • second and third ways are _doable_, yes, but straight against the purpose of this issue report as it forces Swift foundation linking for the whole app

The proper solution would be to drop Swift dependency from the default build binaries and reintroduce Swift-specific builds.

The main issue here is that we want NO Swift runtime libraries being linked to the SDKs and required by depending projects at all as we intend to use these in purely Objective-C or mixed Objective-C/C++ codebase.

https://github.com/facebook/facebook-ios-sdk/pull/1355

This is the conflicting pull request.

Closing since there are already feature requests open for an objc-only distribution.

Hi,

I would like to add that I have opened an issue in Facebook developers:
https://developers.facebook.com/support/bugs/309391336960196/

Which has been closed with the issue unfixed. They have told me to used the older SDK version while waiting for this issue to be fixed.

1425 seems to be the ticket tracking an ObjC-only distribution.

Was this page helpful?
0 / 5 - 0 ratings