firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.54k stars 1.44k forks source link

Undefined symbols when trying to build KMP project #6149

Closed tyczj closed 4 years ago

tyczj commented 4 years ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

Steps to reproduce:

I have a kotlin multiplatform project that I am trying to add firebase to and when I build the project I get this error

Undefined symbols for architecture x86_64:
  "_GULResetLogger", referenced from:
      _FIRResetLogger in FirebaseCore(FIRLogger.o)
  "_GULLoggerRegisterVersion", referenced from:
      ___FIRLoggerInitializeASL_block_invoke in FirebaseCore(FIRLogger.o)
  "_GULLoggerInitializeASL", referenced from:
      ___FIRLoggerInitializeASL_block_invoke in FirebaseCore(FIRLogger.o)
  "_GULLogBasic", referenced from:
      _FIRLogBasic in FirebaseCore(FIRLogger.o)
  "_GULLoggerEnableSTDERR", referenced from:
      ___FIRLoggerInitializeASL_block_invoke in FirebaseCore(FIRLogger.o)
  "_GULLoggerForceDebug", referenced from:
      ___FIRLoggerInitializeASL_block_invoke in FirebaseCore(FIRLogger.o)
  "_OBJC_CLASS_$_GULSceneDelegateSwizzler", referenced from:
      objc-class-ref in FirebaseAuth(FIRAuth.o)
  "_GULIsLoggableLevel", referenced from:
      _FIRIsLoggableLevel in FirebaseCore(FIRLogger.o)
  "_GULSetLoggerLevel", referenced from:
      _FIRSetLoggerLevel in FirebaseCore(FIRLogger.o)
  "_OBJC_CLASS_$_GULAppDelegateSwizzler", referenced from:
      objc-class-ref in FirebaseAuth(FIRAuth.o)
  "_OBJC_CLASS_$_GULAppEnvironmentUtil", referenced from:
      objc-class-ref in FirebaseCore(FIRApp.o)
      objc-class-ref in FirebaseAuth(FIRAuth.o)
      objc-class-ref in FirebaseAuth(FIRAuthAPNSTokenManager.o)
      objc-class-ref in FirebaseCore(FIRBundleUtil.o)
      objc-class-ref in FirebaseAuth(FIRAuthDefaultUIDelegate.o)
ld: symbol(s) not found for architecture x86_64

Relevant Code:

This is my podfile

project 'iosApp.xcodeproj'

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'app' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for app

end

target 'iosApp' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for iosApp
  pod 'Firebase/Auth'
  pod 'Firebase/Analytics'
  pod 'Firebase/Crashlytics'
  pod 'Google-Mobile-Ads-SDK'
  pod 'GooglePlaces'
  pod "Dip"

  target 'iosAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

end
google-oss-bot commented 4 years ago

I found a few problems with this issue:

morganchen12 commented 4 years ago

Looks like you're missing the GoogleUtilities framework. Can you confirm that that's being linked somewhere?

tyczj commented 4 years ago

@morganchen12 What is the pod for that? I didnt see anything in the documentation about needing to add that in

morganchen12 commented 4 years ago

GoogleUtilities is normally included as a dependency of FirebaseCore. If you're using Pods, it's likely already included in your project directory somewhere but just missing from your Xcode configuration.

tyczj commented 4 years ago

@morganchen12 I do see the GoogleUtilities listed in the Pods directory but could you elaborate on the Xcode configuration part a little more? I am not sure what needs to be done here I dont use pods much so I dont know what other configuration there is other than adding the pods.framework to the xcode project

tyczj commented 4 years ago

Also if I take out the firebase dependencies the project compiles no problem and I see the GoogleUtilities pod still there so one of the other google pods I have GooglePlaces or Google-Mobile-Ads-SDK must still use it

paulb777 commented 4 years ago

@tycz Please share the Podfile.lock file

tyczj commented 4 years ago

@paulb777 here is the podfile.lock

PODS:
  - Dip (7.1.1)
  - Firebase/Analytics (6.29.0):
    - Firebase/Core
  - Firebase/Auth (6.29.0):
    - Firebase/CoreOnly
    - FirebaseAuth (~> 6.7.1)
  - Firebase/Core (6.29.0):
    - Firebase/CoreOnly
    - FirebaseAnalytics (= 6.7.0)
  - Firebase/CoreOnly (6.29.0):
    - FirebaseCore (= 6.9.2)
  - Firebase/Crashlytics (6.29.0):
    - Firebase/CoreOnly
    - FirebaseCrashlytics (~> 4.3.1)
  - FirebaseAnalytics (6.7.0):
    - FirebaseCore (~> 6.8)
    - FirebaseInstallations (~> 1.4)
    - GoogleAppMeasurement (= 6.7.0)
    - GoogleUtilities/AppDelegateSwizzler (~> 6.7)
    - GoogleUtilities/MethodSwizzler (~> 6.7)
    - GoogleUtilities/Network (~> 6.7)
    - "GoogleUtilities/NSData+zlib (~> 6.7)"
    - nanopb (~> 1.30905.0)
  - FirebaseAuth (6.7.1):
    - FirebaseCore (~> 6.8)
    - GoogleUtilities/AppDelegateSwizzler (~> 6.7)
    - GoogleUtilities/Environment (~> 6.7)
    - GTMSessionFetcher/Core (~> 1.1)
  - FirebaseCore (6.9.2):
    - FirebaseCoreDiagnostics (~> 1.3)
    - GoogleUtilities/Environment (~> 6.7)
    - GoogleUtilities/Logger (~> 6.7)
  - FirebaseCoreDiagnostics (1.5.0):
    - GoogleDataTransport (~> 7.0)
    - GoogleUtilities/Environment (~> 6.7)
    - GoogleUtilities/Logger (~> 6.7)
    - nanopb (~> 1.30905.0)
  - FirebaseCrashlytics (4.3.1):
    - FirebaseCore (~> 6.8)
    - FirebaseInstallations (~> 1.1)
    - GoogleDataTransport (~> 7.0)
    - nanopb (~> 1.30905.0)
    - PromisesObjC (~> 1.2)
  - FirebaseInstallations (1.5.0):
    - FirebaseCore (~> 6.8)
    - GoogleUtilities/Environment (~> 6.7)
    - GoogleUtilities/UserDefaults (~> 6.7)
    - PromisesObjC (~> 1.2)
  - Google-Mobile-Ads-SDK (7.62.0):
    - GoogleAppMeasurement (~> 6.0)
  - GoogleAppMeasurement (6.7.0):
    - GoogleUtilities/AppDelegateSwizzler (~> 6.7)
    - GoogleUtilities/MethodSwizzler (~> 6.7)
    - GoogleUtilities/Network (~> 6.7)
    - "GoogleUtilities/NSData+zlib (~> 6.7)"
    - nanopb (~> 1.30905.0)
  - GoogleDataTransport (7.1.0):
    - nanopb (~> 1.30905.0)
  - GoogleMaps/Base (3.9.0)
  - GooglePlaces (3.9.0):
    - GoogleMaps/Base (= 3.9.0)
  - GoogleUtilities/AppDelegateSwizzler (6.7.1):
    - GoogleUtilities/Environment
    - GoogleUtilities/Logger
    - GoogleUtilities/Network
  - GoogleUtilities/Environment (6.7.1):
    - PromisesObjC (~> 1.2)
  - GoogleUtilities/Logger (6.7.1):
    - GoogleUtilities/Environment
  - GoogleUtilities/MethodSwizzler (6.7.1):
    - GoogleUtilities/Logger
  - GoogleUtilities/Network (6.7.1):
    - GoogleUtilities/Logger
    - "GoogleUtilities/NSData+zlib"
    - GoogleUtilities/Reachability
  - "GoogleUtilities/NSData+zlib (6.7.1)"
  - GoogleUtilities/Reachability (6.7.1):
    - GoogleUtilities/Logger
  - GoogleUtilities/UserDefaults (6.7.1):
    - GoogleUtilities/Logger
  - GTMSessionFetcher/Core (1.4.0)
  - nanopb (1.30905.0):
    - nanopb/decode (= 1.30905.0)
    - nanopb/encode (= 1.30905.0)
  - nanopb/decode (1.30905.0)
  - nanopb/encode (1.30905.0)
  - PromisesObjC (1.2.9)

DEPENDENCIES:
  - Dip
  - Firebase/Analytics
  - Firebase/Auth
  - Firebase/Crashlytics
  - Google-Mobile-Ads-SDK
  - GooglePlaces

SPEC REPOS:
  trunk:
    - Dip
    - Firebase
    - FirebaseAnalytics
    - FirebaseAuth
    - FirebaseCore
    - FirebaseCoreDiagnostics
    - FirebaseCrashlytics
    - FirebaseInstallations
    - Google-Mobile-Ads-SDK
    - GoogleAppMeasurement
    - GoogleDataTransport
    - GoogleMaps
    - GooglePlaces
    - GoogleUtilities
    - GTMSessionFetcher
    - nanopb
    - PromisesObjC

SPEC CHECKSUMS:
  Dip: 6bebb09d50f88633039ce2c9fe5bc56d387b492f
  Firebase: 57957c8d6eb3d8b80a560b1dc58be24724b89ff2
  FirebaseAnalytics: aa522dce9fd93002ba1554467d23ce7092323000
  FirebaseAuth: a818d73466d51db897d3bf3c0f3baa3dae7fd4c0
  FirebaseCore: 7930a1946517d94256d857f97371ed993b55f7bd
  FirebaseCoreDiagnostics: 7535fe695737f8c5b350584292a70b7f8ff0357b
  FirebaseCrashlytics: 863c851b034baeb3116cd2c91743e37de2dcedfc
  FirebaseInstallations: 3c520c951305cbf9ca54eb891ff9e6d1fd384881
  Google-Mobile-Ads-SDK: c92c27666fbf684c964259785a6b3cdd3068e06f
  GoogleAppMeasurement: 345d365fd105e6682bf5084783a5352a3db26820
  GoogleDataTransport: af0c79193dc59acd37630b4833d0dc6912ae6bd5
  GoogleMaps: 4b5346bddfe6911bb89155d43c903020170523ac
  GooglePlaces: 1634d019549b969d40fe0ccb0b9513055adebe01
  GoogleUtilities: e121a3867449ce16b0e35ddf1797ea7a389ffdf2
  GTMSessionFetcher: 6f5c8abbab8a9bce4bb3f057e317728ec6182b10
  nanopb: c43f40fadfe79e8b8db116583945847910cbabc9
  PromisesObjC: b48e0338dbbac2207e611750777895f7a5811b75

PODFILE CHECKSUM: 465f2502a31bbab6398f0920d0c98034f34e6379

COCOAPODS: 1.9.1
paulb777 commented 4 years ago

Hmm, the GoogleUtilities subspecs that define those missing symbols look to be installed.

Are there any additional builder warnings or errors?

It might be helpful to flush all the CocoaPods and Xcode state.

tyczj commented 4 years ago

@paulb777 Another bit of information here, it seems that if I just install the pods everything compiles fine BUT I get the errors as soon as I try to use something,

for example this is the class I an trying to create

import Firebase

class AuthServiceImpl : AuthService{
    func getCurrentUser(handler: @escaping (User?) -> Void) {
        let user = Auth.auth().currentUser
//
//        if(user == nil){
//            Auth.auth().signInAnonymously(completion: { (authResult, error) in
//                handler(authResult?.user)
//            })
//        }else{
//            handler(user!)
//        }
    }
}

If I comment out the line let user = Auth.auth().currentUser it builds but as soon as that is in there I get the errors

paulb777 commented 4 years ago

That sounds really strange. We might not be able to solve here unless you're able to reproduce in Swift or Objective C. The issue might be better researched in the KMP community.

morganchen12 commented 4 years ago

That's normal, if your code doesn't reference any of the missing symbols the linker will just strip them and not complain.

Can you try adding -framework GoogleUtilities in your project's build settings under Other Linker Flags? This should attempt to force-include the framework and will give you a hopefully informative error if it's unable to.

tyczj commented 4 years ago

@morganchen12 I added that flag (with a small change, I added "" around GoogleUtilities) and it compiles now