Problems with Firebase and SwiftUI Live Previews
Asked Answered
H

3

11

Since I added Firebase to my project Live Previews no longer work. Regular builds do work, just no live previews.

I tried following all of this answer solutions and comments with no luck (that question has the same errors although unrelated to SwiftUI).

Diagnostics:

linker command failed with exit code 1 (use -v to see invocation)


LinkDylibError: Failed to build UserViews.swift

Linking failed: linker command failed with exit code 1 (use -v to see invocation)

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)
Higley answered 27/2, 2020 at 19:1 Comment(2)
The question you linked is unrelated to SwiftUI and was from 2017. Are you sure that was the right question/answers?Jenifferjenilee
Can you see any error? Try checking Diagnostics button next to Try Again button.Chetnik
H
8

For now I have to temporarily disable Firebase (and GoogleSignIn) to work with SwiftUI's Live Previews.

In my case I use Cocoapods, so I comment out the libraries from my Podfile:

#  pod 'Firebase/Analytics'
#  pod 'Firebase/Crashlytics'
#  pod 'Firebase/Messaging'
#  pod 'GoogleSignIn'

Then $ pod install to temporarily remove them.

And finally use #if canImport(Firebase) (and #if canImport(GoogleSignIn)) preprocessor macros where needed.

#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

Not optimal, but until Xcode 12 fixes it or Google updates its frameworks no other way around it.

Higley answered 6/5, 2020 at 16:5 Comment(1)
That's crazy as it's not fixed yet. It's Jan 2021.Monteiro
S
10

Try Disable Code Coverage for the scheme.

This worked for me.

On Xcode 11.3 I've been able to get SwiftUI Previews building by simply disabling Code Coverage gathering for my scheme. The above solutions weren't working as I was still getting "failedToBuildDylib" errors for Firebase. In fact, the above fixes don't seem to be necessary at all, at least on my case. Hope this helps someone.

Credits to: https://twitter.com/dannypier/status/1190312160557068293

Scrimmage answered 13/6, 2020 at 4:23 Comment(0)
H
8

For now I have to temporarily disable Firebase (and GoogleSignIn) to work with SwiftUI's Live Previews.

In my case I use Cocoapods, so I comment out the libraries from my Podfile:

#  pod 'Firebase/Analytics'
#  pod 'Firebase/Crashlytics'
#  pod 'Firebase/Messaging'
#  pod 'GoogleSignIn'

Then $ pod install to temporarily remove them.

And finally use #if canImport(Firebase) (and #if canImport(GoogleSignIn)) preprocessor macros where needed.

#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

Not optimal, but until Xcode 12 fixes it or Google updates its frameworks no other way around it.

Higley answered 6/5, 2020 at 16:5 Comment(1)
That's crazy as it's not fixed yet. It's Jan 2021.Monteiro
F
1

Install firebase using SPM (use the beta branch because its still beta until now) and remove CocoPods .. and previews will work again perfectly

Here is the link for installing firebase via SPM https://github.com/firebase/firebase-ios-sdk/blob/master/SwiftPackageManager.md

Flexible answered 5/10, 2020 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.