Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use with Pods (firebase) #79

Open
marcoizzo opened this issue Jan 18, 2018 · 39 comments
Open

Use with Pods (firebase) #79

marcoizzo opened this issue Jan 18, 2018 · 39 comments

Comments

@marcoizzo
Copy link

marcoizzo commented Jan 18, 2018

Hi guys,

thanks for this component.

I'm trying to implement a share extension with a firebase-based app. So I have created a pod file and generated a .xcworkspace project.

I followed all installation tutorial and all seem ok, but when I try to launch the extension Xcode console says:

RNFirebase core module was not found natively on iOS, ensure you have correctly included the RNFirebase pod in your projects 'Podfile' and have run 'pod install'.

This is my pod file:

target 'Together' do
  # Pods for Together
  pod 'Firebase/Core'
  pod 'Firebase/Auth'
  pod 'Firebase/Firestore'
  pod 'Firebase/Messaging'
  pod 'Firebase/Storage'

  pod "QBImagePickerController"
  
end

target 'TogetherShareEx' do

  # Pods for TogetherShareEx
  pod 'Firebase/Core'
  pod 'Firebase/Auth'
  pod 'Firebase/Firestore'
  pod 'Firebase/Storage'

end

And this my TogetherShareEx.m

#import <Foundation/Foundation.h>
#import "ReactNativeShareExtension.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLog.h>
#import <Firebase.h>

@interface TogetherShareEx : ReactNativeShareExtension
@end

@implementation TogetherShareEx

RCT_EXPORT_MODULE();

- (UIView*) shareView {
  
  NSURL *jsCodeLocation;
  
  [FIRApp configure];
  
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"TogetherShareEx"
                                               initialProperties:nil
                                                   launchOptions:nil];
  rootView.backgroundColor = nil;
    
  return rootView;
}

@end

I have also addedd:

  • added '$(inherited)' in Other Linker Flags
  • added '$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase' in Header Search Paths

Any idea? Thanks

@dolphinflow86
Copy link

Same issue here.

@alexkuttig
Copy link

Did you include the RNFirebase Project in your extension's build target Link Binary With Libraries? It seems like Firebase is installed correctly but you native RNFirebase Project is missing...

@marcoizzo
Copy link
Author

marcoizzo commented Mar 6, 2018

I've solved with the creation of an app group between the app and the extension

@BigPun86
Copy link

@marcoizzo can you explain me exactly what you mean? I am not really sure how to do this :)

@marcoizzo
Copy link
Author

@BigPun86 you have to create an app group. To do this:

  1. Click on you project name under navigator
  2. Click on your target > Capabilities tab > Enable App Groups
  3. Do same operations with app extension target

Then add linked framework and libraries required (libRNFirebase.h) under general tab

I hope this useful :)

@BigPun86
Copy link

BigPun86 commented Mar 13, 2018

@marcoizzo Unfortunately it didn´t help. But thanks for your explanation. I am using Crashlytics aas well in my pods. I tried to add both libRNFirebase & lib..Crashlytics. I still receive the errors and it wont build my project. I f i remove crashlytics and firebase as linked libraries it will build, but then the app hangs as soon as i share something (URL or Image). Any ideas how to fix that? I mean, do you think this is because i didn´t link CrashLytics and Firebase?

@marcoizzo
Copy link
Author

marcoizzo commented Mar 13, 2018

@BigPun86 what's the error during building? Anyway, you have to include Firebase and CrashLytics in your extension if you have to use them in your code

@BigPun86
Copy link

BigPun86 commented Mar 13, 2018

@marcoizzo this is the error i am getting:

screen shot 2018-03-13 at 15 12 53

This is how my PodFile looks like:

target 'SomeApp' do
  pod 'FirebaseMessaging'
  pod 'Fabric'
  pod 'Crashlytics'

  target 'SomeAppShare' do
    inherit! :search_paths
    pod 'FirebaseMessaging'
    pod 'Fabric'
    pod 'Crashlytics'
  end

  target 'SomeAppTests' do
    inherit! :search_paths
  end
end

@marcoizzo
Copy link
Author

@BigPun86 Do you have added -ObjC and -lc++ as linker flags?

@BigPun86
Copy link

@marcoizzo i added it to the Share Target, yes.

@marcoizzo
Copy link
Author

@BigPun86 mmm... it seem that the problem is Fabric, but I have never used it so I don't know... Try to remove it in your extension to understand if really crashlytics is the issue

@BigPun86
Copy link

BigPun86 commented Mar 13, 2018

@marcoizzo now i am getting some React related issues. Maybe u can show me how you have set up your Header Search Path?

This is how mine looks right now:

screen shot 2018-03-13 at 15 23 46

@marcoizzo
Copy link
Author

This is mine
schermata 2018-03-13 alle 15 27 24

@BigPun86
Copy link

@marcoizzo many thanks, i will check it. So actually your Header Search stuff is exactly the same as the one you use for your main target app?

@marcoizzo
Copy link
Author

@BigPun86 Yep!

@daviswhitehead
Copy link

@marcoizzo Any more information you can share on your successful setup? I would really appreciate any help you can give towards adding rnfirebase!

I've previously got the share extension working without rnfirebase. Below is some information about my attempt to integrate rnfirebase.

Share Extension
ShareExtension.m
image

Header Search Paths
image

Linked Frameworks and Libraries
image

Main App
Header Search Paths
image

Linked Frameworks and Libraries
image

Podfile
image

@BigPun86
Copy link

@daviswhitehead could you atleast build without issues, or does this already fail?

@daviswhitehead
Copy link

I can build successfully without trying to integrate rnfirebase. But when I do, I get the following error, which I believe you were seeing as well right @BigPun86 ?
image

@BigPun86
Copy link

BigPun86 commented Apr 15, 2018

@daviswhitehead yeah, i had exactly the same issue. i cant remember what exactly i have done which fixed it...but i think it was enabling AppGroups and/or first cleaning and then building the ShareExtension target/app, maybe you can just try that. If not i hope my setup will help you:

Linked Libraries and Header Search Path setup of the main App:
screen shot 2018-04-15 at 23 31 10

screen shot 2018-04-15 at 23 31 01

Linked Libraries and Header Search Path setup of the Share Extension:
screen shot 2018-04-15 at 23 30 51
screen shot 2018-04-15 at 23 30 29

@daviswhitehead
Copy link

@BigPun86 what does your appgroup look like? does this look correct to you? (both the main app and extension look the same)

image

@daviswhitehead
Copy link

I'm getting the same error regardless of if I have App Groups on or off. Any ideas?

@BigPun86
Copy link

BigPun86 commented Apr 15, 2018

@daviswhitehead yes, but you have to enable it for both, the ShareExtension & the Main App. Then run pod install again and maybe also react-native link...

@daviswhitehead
Copy link

Yep I've enabled for both and am getting the same error.

@BigPun86
Copy link

@daviswhitehead did you run pod install & react-native link after your changes too?

@daviswhitehead
Copy link

Unfortunately, yes I have and am still on that same error.

@daviswhitehead
Copy link

I think it's failing before hitting anything related to App Groups. I get the same error when App Groups is off for both (main and share extension) targets.

I'm not super familiar with xcode or native iOS dev, but it seems like libRNFirebase.a is not able to find all the nested references. My code seems to be failing at the #import <Firebase.h> line of ShareExtension.m. $(inherited) and $(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase in the share extension's header search paths does not seem to help at all.

@daviswhitehead
Copy link

I was able to get the firebase pods linked by removing all pods under the extension and adding the line inherit! :complete.
However, the extension is now failing at [FIRApp configure]; in the ShareExtension.m file. Upon debugging, my thread get's killed
image
and I get the following output Message from debugger: Terminated due to signal 6

Any ideas @BigPun86 or @marcoizzo ?

@daviswhitehead
Copy link

Figured it out! I solved the latest problem by adding the GoogleService-Info.plist file into the ShareExtension folder like so.
image

My podfile looks like this
image

@emilefleming
Copy link

@daviswhitehead I'm experiencing the same linker error you were at first:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_FIRMessaging", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseMessaging.o)
  "_OBJC_CLASS_$_FIRTransactionResult", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseDatabase.o)
  "_OBJC_CLASS_$_FIRDatabase", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseDatabase.o)
  "_OBJC_CLASS_$_FIRAnalyticsConfiguration", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAnalytics.o)
  "_OBJC_CLASS_$_FIRAnalytics", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAnalytics.o)
  "_OBJC_CLASS_$_FIRGitHubAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIREmailAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRFacebookAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRActionCodeSettings", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRInstanceID", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseInstanceId.o)
      objc-class-ref in libRNFirebase.a(RNFirebaseMessaging.o)
  "_OBJC_CLASS_$_FIRAuth", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRTwitterAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIROptions", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebase.o)
  "_OBJC_CLASS_$_FIROAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRApp", referenced from:
      objc-class-ref in ShareExtension.o
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
      objc-class-ref in libRNFirebase.a(RNFirebase.o)
      objc-class-ref in libRNFirebase.a(RNFirebaseUtil.o)
  "_OBJC_CLASS_$_FIRPhoneAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRGoogleAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Do you recall if there were any steps you took to resolve it that weren't mentioned in this thread?

The extension portion of my podfile looks like this:

target 'ShareExtension' do
  inherit! :complete
end

Linker flags are set correctly.

In my header search paths for the extension I have

$(inherited)
$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase
$(SRCROOT)/../node_modules/react-native-share-extension/ios

Under Build Phases > Link Binary with Libraries I have libRNFirebase.a and libPods-ShareExtension.a

Does anything else come to mind that I might try?

Interestingly enough when I remove firebase I am able to build but get a runtime error related to firebase, even if I don't import it in ShareExtension.m

@AndrewHenderson
Copy link
Collaborator

For anyone struggling with this issue. After following the standard installation instructions, make sure you do the following:

  1. Link libRNFirebase.a in your Extension's Build Phases.
    Also, make sure that libPods-{YOUR_EXTENSION_NAME}.a is linked as well.
  2. Set the GoogleService-Info.plist target for both your main app and your share extension in the right panel.
  3. In your share extension's Build Settings > Other Linker Flags, make sure you add $(inherited)
  4. In your Share Extension .m file, make sure you import Firebase and configure it there as well!
#import <Firebase.h>
- (UIView*) shareView {
  NSURL *jsCodeLocation;
  [FIRApp configure];
  …
}

@i25878427
Copy link

@AndrewHenderson Do you know if it is possible to authenticate with firebase from the main app and some how pass the authentication to the share extension? (I don't want to ask the user to do login again)

@AndrewHenderson
Copy link
Collaborator

@i25878427 Use react-native-shared-group-preferences. For iOS you'll need to create an "App Group" and give both your app and the extension permission. This has to be done in Xcode. The install steps should cover everything.

@i25878427
Copy link

@AndrewHenderson Thanks for the help :-). I already have "App Group" installed and I was able to share data between the main app and the share extension.

Maybe my question is more firebase related. I don't know what should I share with the share extension from the main app to make the share extension authenticate with firebase, so I can read/write to firebase database.

@AndrewHenderson
Copy link
Collaborator

@i25878427 I've found that the Share extension has its own scope and any modules have separate instances — so your Firebase instance would probably have to be initialized for both.

The only data I've been able to share is storing strings in the App Group.

You're better off asking these questions in https://github.com/invertase/react-native-firebase. They also have their own channel on Discord. Good luck! 😄

@i25878427
Copy link

@AndrewHenderson Thanks! I will try using their channel :-)

@daviswhitehead
Copy link

not totally sure how this works technically, but I was able to authenticate with firestore through the share extension in the same way I do within my main app. Not sure if it's any different for firebase but would guess not.

this.authSubscription = firebase.auth().onAuthStateChanged((user) => { this.setState((previousState) => { return { ...previousState, loading: false, user: user, } }) });

@AndrewHenderson
Copy link
Collaborator

That seems right. I’d expect you’d need to authenticate the same way, but that there would be separate configured firebase instances — so they would not share a session.

Did you have to auth through share extension separately? Do you have to reauthenticate in the share extension every time?

@kdepp
Copy link

kdepp commented Nov 3, 2018

In your share extension's Build Settings > Other Linker Flags, make sure you add $(inherited)

Adding ${inherited} fixed my problem. Thanks for your info, @AndrewHenderson

@kodeCoala
Copy link

@daviswhitehead I'm experiencing the same linker error you were at first:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_FIRMessaging", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseMessaging.o)
  "_OBJC_CLASS_$_FIRTransactionResult", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseDatabase.o)
  "_OBJC_CLASS_$_FIRDatabase", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseDatabase.o)
  "_OBJC_CLASS_$_FIRAnalyticsConfiguration", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAnalytics.o)
  "_OBJC_CLASS_$_FIRAnalytics", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAnalytics.o)
  "_OBJC_CLASS_$_FIRGitHubAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIREmailAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRFacebookAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRActionCodeSettings", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRInstanceID", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseInstanceId.o)
      objc-class-ref in libRNFirebase.a(RNFirebaseMessaging.o)
  "_OBJC_CLASS_$_FIRAuth", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRTwitterAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIROptions", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebase.o)
  "_OBJC_CLASS_$_FIROAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRApp", referenced from:
      objc-class-ref in ShareExtension.o
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
      objc-class-ref in libRNFirebase.a(RNFirebase.o)
      objc-class-ref in libRNFirebase.a(RNFirebaseUtil.o)
  "_OBJC_CLASS_$_FIRPhoneAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
  "_OBJC_CLASS_$_FIRGoogleAuthProvider", referenced from:
      objc-class-ref in libRNFirebase.a(RNFirebaseAuth.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Do you recall if there were any steps you took to resolve it that weren't mentioned in this thread?

The extension portion of my podfile looks like this:

target 'ShareExtension' do
  inherit! :complete
end

Linker flags are set correctly.

In my header search paths for the extension I have

$(inherited)
$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase
$(SRCROOT)/../node_modules/react-native-share-extension/ios

Under Build Phases > Link Binary with Libraries I have libRNFirebase.a and libPods-ShareExtension.a

Does anything else come to mind that I might try?

Interestingly enough when I remove firebase I am able to build but get a runtime error related to firebase, even if I don't import it in ShareExtension.m

I am facing the same issue. @emilefleming did you end up resolving this ? @AndrewHenderson I followed all the instructions listed as well.

Here is how my pod file looks -

#import <Foundation/Foundation.h>
#import "ReactNativeShareExtension.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLog.h>
#import <Firebase.h>

@interface ShareExt : ReactNativeShareExtension
@end

@implementation ShareExt

RCT_EXPORT_MODULE();

- (UIView*) shareView {
  NSURL *jsCodeLocation;
  [FIRApp configure];
  
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"ShareExtApp"
                                               initialProperties:nil
                                                   launchOptions:nil];
  rootView.backgroundColor = nil;
  
  // Uncomment for console output in Xcode console for release mode on device:
  RCTSetLogThreshold(RCTLogLevelInfo - 1);
  
  return rootView;
}

@end

Any help appreciated!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants