invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.7k stars 2.22k forks source link

Undefined symbols on iOS w/ RN 0.60.3's autolinking feature #2356

Closed jorisw closed 5 years ago

jorisw commented 5 years ago

Issue

Possibly related to #2353:

I can't build my React Native 0.60.3 project with React Native Firebase 5.5.5:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_FIRApp", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_RNFirebaseMessaging", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_RNFirebaseNotifications", referenced from:
      objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

react-native-firebease is currently the only installed package that fails in this manner.

I have cleared my Other Linker Flags settings in Xcode, which used to contain $(inherited), which with RN0.60's new autolinking feature, would generate duplicate symbols for every linked package:

duplicate symbol _OBJC_CLASS_$_RCTVibration in:
    /Users/jorisw/Projects/xxx/xxx-frontend/ios/build/xxx/Build/Products/Debug-iphonesimulator/React-RCTVibration/libReact-RCTVibration.a(RCTVibration.o)
    /Users/jorisw/Projects/xxx/xxx-frontend/ios/build/xxx/Build/Products/Debug-iphonesimulator/libRCTVibration.a(RCTVibration.o)
...
duplicate symbol _OBJC_IVAR_$_RCTWebSocketExecutor._bridge in:
    /Users/jorisw/Projects/xxx/xxx-frontend/ios/build/xxx/Build/Products/Debug-iphonesimulator/React-RCTWebSocket/libReact-RCTWebSocket.a(RCTWebSocketExecutor.o)
    /Users/jorisw/Projects/xxx/xxx-frontend/ios/build/xxx/Build/Products/Debug-iphonesimulator/libRCTWebSocket.a(RCTWebSocketExecutor.o)
...
ld: 1309 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Project Files

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # Uncomment the next line to define a global platform for your project platform :ios, '9.0' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' target 'xxx' do # Uncomment the next line if you're using Swift or would like to use dynamic frameworks # use_frameworks! # Pods for xxx pod 'React', :path => '../node_modules/react-native/' pod 'React-Core', :path => '../node_modules/react-native/React' pod 'React-DevSupport', :path => '../node_modules/react-native/React' pod 'React-fishhook', :path => '../node_modules/react-native/Libraries/fishhook' pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation' pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob' pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image' pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network' pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings' pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text' pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration' pod 'React-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSocket' pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact' pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi' pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor' pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector' pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga' pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' pod 'TrustKit', '~> 1.4.2' pod 'CertPinner', :git => 'https://github.com/approov/react-native-cert-pinner.git' pod 'GoogleIDFASupport', '~> 3.14.0' pod 'Firebase/Core', '~> 6.3.0' pod 'Firebase/Analytics', '~> 6.3.0' pod 'Firebase/Messaging', '~> 6.3.0' target 'xxxTests' do inherit! :search_paths # Pods for testing end use_native_modules! end target 'xxx-tvOS' do # Pods for RnDiffApp-tvOS target 'xxx-tvOSTests' do inherit! :search_paths # Pods for testing end end ``` #### `AppDelegate.m`: ```objc /** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #import "AppDelegate.h" #import #import #import #import #import #import #import "RNFirebaseNotifications.h" #import "RNFirebaseMessaging.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRApp configure]; [RNFirebaseNotifications configure]; RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"xxx" initialProperties:nil]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; return YES; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{ [[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings]; } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification]; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } // Handle deeplinks - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; } @end ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 10.14.5 CPU: (4) x64 Intel(R) Core(TM) i7-6660U CPU @ 2.40GHz Memory: 74.97 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 12.1.0 - /usr/local/bin/node Yarn: 1.16.0 - /usr/local/bin/yarn npm: 6.9.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2 Android SDK: API Levels: 23, 24, 25, 26, 27, 28 Build Tools: 20.0.0, 25.0.1, 25.0.2, 26.0.3, 27.0.3, 28.0.0, 28.0.3 System Images: android-22 | ARM EABI v7a, android-24 | ARM EABI v7a, android-24 | Intel x86 Atom_64, android-24 | Google APIs Intel x86 Atom_64, android-24 | Google Play Intel x86 Atom, android-25 | Google APIs Intel x86 Atom_64 IDEs: Android Studio: 3.3 AI-182.5107.16.33.5264788 Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild npmPackages: react: 16.8.6 => 16.8.6 react-native: 0.63 => 0.60.3 npmGlobalPackages: react-native-cli: 2.0.1 ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [ ] Android - [x] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `5.5.5` - **Are you using `TypeScript`?** - `Y`


Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

jorisw commented 5 years ago

Tried suggestion in https://github.com/invertase/react-native-firebase/issues/2354, didn't work

JerakRus commented 5 years ago

I get the same error.

JerakRus commented 5 years ago

If I remove the search path of 'react-native-firebase / ios' in build settings, the error goes away, but another "RNFirebaseNotifications.h 'file not found' " appears.

jorisw commented 5 years ago

I've fixed my Xcode project as follows:

Your build may now crash on duplicate symbols if you were already using CocoaPods before you upgraded React Native. To fix this, following the hint at https://github.com/facebook/react-native/issues/23613#issuecomment-499341062 :

The app should now build.

eltonea commented 5 years ago

Still happens to me :(

👇

App/ios/build/App/Build/Products/Debug-iphonesimulator/RNFBApp/RNFBApp.framework/RNFBApp
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_GULAppEnvironmentUtil", referenced from:
      objc-class-ref in FirebaseCore(FIRBundleUtil.o)
  "_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)
  "_GULIsLoggableLevel", referenced from:
      _FIRIsLoggableLevel in FirebaseCore(FIRLogger.o)
  "_GULSetLoggerLevel", referenced from:
      _FIRSetLoggerLevel in FirebaseCore(FIRLogger.o)
  "_GULLoggerForceDebug", referenced from:
      ___FIRLoggerInitializeASL_block_invoke in FirebaseCore(FIRLogger.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Some idea?

jrnk commented 5 years ago

use_frameworks! is (still?) not playing nice with this library (6.0.3) under RN 0.61.2. I've solved it for now by linking the needed frameworks in a post_install:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if ['RNFBApp', 'RNFBMessaging'].include?(target.name)
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GoogleUtilities'})
    elsif target.name.eql?('RNFBAnalytics')
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'FirebaseAnalytics'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GoogleAppMeasurement'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'nanopb'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GoogleUtilities'})
    end
  end
end
mikehardy commented 5 years ago

@jrnk without specifying the versions of everything you're using this advice may not be useful. use_frameworks support is in flux between rn59, 60, and 61, and the react-native-firebase version is also likely important

jrnk commented 5 years ago

@mikehardy good point, I've edited the comment to reflect that (rn-fb 6.0.3 and rn 0.61.2)

mikehardy commented 5 years ago

...and unfortunately you are completely current so it's a shame use_frameworks is still so problematic :-). One of these days...

llaine commented 4 years ago

Getting the same issue with react-native 0.61.4 and react-native-firebase 6.1.0, however @jrnk post_install trick did the job.

andrei-zgirvaci commented 4 years ago

@llaine thanks for your solution, it helped me fix it for RNFBApp, but, how do I fix it for my other dependencies. I am currently using the following dependencies: ['RNFBApp', 'RNFBAuth', 'RNFBFirestore', 'RNFBStorage', 'RNFBDynamicLinks', 'RNFBPerf', 'RNFBAnalytics', 'RNFBCrashlytics'] ?

p.s How do I find out which system frameworks I need to add to each target, so I can fix it myself in the future if I decide to use other frameworks?

Aurelienlajoinie commented 4 years ago

Hello, I'm using this on my project:

  installer.pods_project.targets.each do |target|
    if ['RNFBApp', 'RNFBMessaging' ].include?(target.name)
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GoogleUtilities'})
    elsif ['RNFBCrashlytics'].include?(target.name)
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'Fabric'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'Crashlytics'})
    elsif target.name.eql?('RNFBAnalytics')
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'FirebaseAnalytics'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GoogleAppMeasurement'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'nanopb'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GoogleUtilities'})
    elsif target.name.eql?('RNFBPerf')
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'FirebasePerformance'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'FirebaseSwizzlingUtilities'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GTMSessionFetcher'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GoogleDataTransport'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GoogleDataTransportCCTSupport'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GoogleToolboxForMac'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'GoogleUtilities'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'Protobuf'})
      target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'nanopb'})
    end
  end

Build is ok but i've an error at startup with FIRApp initialization and don't know if the problem come from pod install :s ([FIRApp configure] is ok in appDelegate.m file)

mikem3d commented 4 years ago

@Aurelienlajoinie I'm having the same exact issue. We have to use use_frameworks! for other dependencies. We are able to build using the add_system_framework solution described above, but we see a crash on init with [Firebase/Core][I-COR000005] No app has been configured yet.

Config file is correctly included and the library is initialized as well with if ([FIRApp defaultApp] == nil) { [FIRApp configure]; }

No dice.

Aurelienlajoinie commented 4 years ago

@mikem3d i was able to fix this using this Podfile:

use_frameworks!
 ....

target 'myTarget' do
  use_native_modules!

pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  .....
end

pre_install do |installer|
  installer.pod_targets.each do |pod|
    if pod.name.start_with?('RNFB')
      def pod.build_type;
        Pod::Target::BuildType.static_library
      end
    end
  end
end

Hope it can help you :)

mikem3d commented 4 years ago

@Aurelienlajoinie that worked! should be pinned and added to documentation! def pod.build_type; Pod::Target::BuildType.static_library end

mikehardy commented 4 years ago

I think getting it to work with use_frameworks in general could use a full documentation page that consolidates all the known-required workarounds - it is a huge source of issue traffic here and could help lots of people if someone wanted to start a gist that grouped them all together?

alshirokov81 commented 4 years ago

@Aurelienlajoinie that worked for me just for another library, not for firebase. Thank You!!!

a2lop commented 3 years ago

@mikem3d i was able to fix this using this Podfile:

use_frameworks!
 ....

target 'myTarget' do
  use_native_modules!

pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  .....
end

pre_install do |installer|
  installer.pod_targets.each do |pod|
    if pod.name.start_with?('RNFB')
      def pod.build_type;
        Pod::Target::BuildType.static_library
      end
    end
  end
end

Hope it can help you :)

This works for me! but just I had to change Pod::Target::BuildType.static_library to Pod::BuildType.static_library, thanks!