Firebase 和 SwiftUI 实时预览的问题

Riv*_*era 10 live-preview ios firebase swiftui

由于我将 Firebase 添加到我的项目中,实时预览不再有效。常规构建确实有效,只是没有实时预览。

我尝试按照所有这些答案解决方案和评论进行操作,但没有运气(尽管与 SwiftUI 无关,但该问题有相同的错误)。

诊断:

链接器命令失败,退出代码为 1(使用 -v 查看调用)


LinkDylibError:无法构建 UserViews.swift

链接失败:链接器命令失败,退出代码为 1(使用 -v 查看调用)

ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator'
Undefined symbols for architecture x86_64:
  "___llvm_profile_runtime", referenced from:
      ___llvm_profile_runtime_user in FirebaseCore(FIRAppAssociationRegistration.o)
      ___llvm_profile_runtime_user in FirebaseCore(FIRComponentType.o)
      ___llvm_profile_runtime_user in FirebaseCore(FIRConfiguration.o)
      ___llvm_profile_runtime_user in FirebaseCore(FIRCoreDiagnosticsConnector.o)
      ___llvm_profile_runtime_user in FirebaseCore(FIRDiagnosticsData.o)
      ___llvm_profile_runtime_user in FirebaseCore(FirebaseCore-dummy.o)
      ___llvm_profile_runtime_user in FirebaseCore(FIROptions.o)
      ...
     (maybe you meant: ___llvm_profile_runtime_user)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

Riv*_*era 8

现在我必须暂时禁用 Firebase(和 GoogleSignIn)才能使用 SwiftUI 的实时预览。

在我的例子中,我使用 Cocoapods,所以我从我的 Podfile 中注释掉了这些库:

#  pod 'Firebase/Analytics'
#  pod 'Firebase/Crashlytics'
#  pod 'Firebase/Messaging'
#  pod 'GoogleSignIn'
Run Code Online (Sandbox Code Playgroud)

然后$ pod install暂时删除它们。

最后在需要的地方使用#if canImport(Firebase)(和#if canImport(GoogleSignIn))预处理器宏。

#if canImport(Firebase)
import Firebase
#endif
#if canImport(GoogleSignIn)
import GoogleSignIn
#endif

// ...

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
    // ...

    #if canImport(Firebase)
    FirebaseApp.configure()
    #endif
Run Code Online (Sandbox Code Playgroud)

不是最优的,但在 Xcode 12 修复它或谷歌更新其框架之前别无他法。


小智 6

尝试禁用该方案的代码覆盖率

这对我有用。

在 Xcode 11.3 上,我可以通过简单地禁用我的方案的代码覆盖率收集来构建 SwiftUI 预览。上述解决方案不起作用,因为我仍然收到 Firebase 的“failedToBuildDylib”错误。事实上,至少在我的情况下,上述修复似乎根本没有必要。希望这可以帮助某人。

致谢:https : //twitter.com/dannypier/status/1190312160557068293