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.72k stars 2.22k forks source link

RNFirebase core module was not found natively on iOS - migrating from react-native-firebase v5 to v6 #4035

Closed co-de closed 4 years ago

co-de commented 4 years ago

Issue

I am getting "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" error when the app starts on Ios simulator. Pod installation and build are completed just fine.


Project Files

This is my podfile:

    # Uncomment the next line to define a global platform for your project
$RNFirebaseAsStaticFramework = true
platform :ios, '11.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
use_frameworks!

target 'application' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  #use_frameworks!
  #use_modular_headers!

  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 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  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-Core/RCTWebSocket', :path => '../node_modules/react-native/'
  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 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"  
  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 'RNCharts', :path => '../node_modules/react-native-charts-wrapper'
  pod 'QBImagePickerController', :path => '../node_modules/react-native-image-crop-picker/ios/QBImagePicker/QBImagePickerController.podspec'
  pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler'
  pod 'RNImageCropPicker', :path => '../node_modules/react-native-image-crop-picker'
  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
  pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen'
  pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo'
  pod 'Firebase'

# pod 'Firebase/Core', '~> 6.3.0'
# pod 'Firebase/Messaging'
# pod 'Firebase/Analytics'
# pod 'Firebase/DynamicLinks'
# pod 'Firebase/Messaging', '~> 6.27.0'

# FBSDK
# pod 'FBSDKCoreKit'
# pod 'FBSDKLoginKit'
# pod 'FBSDKShareKit'

# RNGestureHandler
# RNVectorIcons

pre_install do |installer|
    installer.analysis_result.specifications.each do |s|
        s.swift_version = '5.0' unless s.swift_version
    end
end

#post_install do |installer|
#  rnfirebase = installer.pods_project.targets.find { |target| target.name == 'RNFirebase' }
#  rnfirebase.build_configurations.each do |config|
#    config.build_settings['HEADER_SEARCH_PATHS'] = '$(inherited) ${PODS_ROOT}/Headers/Public/**'
#  end
#end

use_native_modules!

This is my package.json:

{
  "name": "application",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@babel/runtime": "^7.4.3",
    "@react-native-community/netinfo": "^5.0.0",
    "@react-native-firebase/app": "^8.2.0",
    "@react-native-firebase/messaging": "^7.5.0",
    "firebase": "^5.11.1",
    "flatted": "^2.0.1",
    "react": "16.9.0",
    "react-native": "0.61.2",
    "react-native-charts-wrapper": "^0.5.1",
    "react-native-elements": "^1.1.0",
    "react-native-fbsdk": "^2.0.0",
    "react-native-gesture-handler": "1.4.1",
    "react-native-image-crop-picker": "^0.24.1",
    "react-native-keyboard-aware-scroll-view": "^0.8.0",
    "react-native-multiple-select": "^0.5.3",
    "react-native-radio-buttons": "^1.0.0",
    "react-native-screens": "^2.8.0",
    "react-native-splash-screen": "^3.2.0",
    "react-native-vector-icons": "^6.6.0",
    "react-navigation": "^3.3.2",
    "react-redux": "^6.0.1",
    "redux": "^4.0.1",
    "redux-persist": "^5.10.0",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

I don't seem to have firebase.json file. I see this message:

A firebase.json file was not found, whilst this file is optional it is recommended to include it to configure firebase services in React Native Firebase

This is my AppDelegate.m:

/**
 * 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 <Firebase.h>//

//#import "RNFirebaseNotifications.h"//
//#import "RNFirebaseMessaging.h"//

#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  //  [FIRApp configure];//

  // Add me --- \/
  if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
  }
  // Add me --- /\
  // ...

  //  [FIRMessaging messaging].autoInitEnabled = YES;// added for fcm notifications
  //  [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
  //  [RNFirebaseNotifications configure];//
  NSURL *jsCodeLocation;

  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"application"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [UIColor blackColor];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  [[FBSDKApplicationDelegate sharedInstance] application:application
                           didFinishLaunchingWithOptions:launchOptions];

  //added for fcm notifications
  if ([UNUserNotificationCenter class] != nil) {
    // iOS 10 or later
    // For iOS 10 display notification (sent via APNS)
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
    UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
        UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
    [[UNUserNotificationCenter currentNotificationCenter]
        requestAuthorizationWithOptions:authOptions
        completionHandler:^(BOOL granted, NSError * _Nullable error) {
          // ...
          printf("xxxxxxxxxxxxxxxxxxxx UNUserNotificationCenter requestAuthorizationWithOptions error \(error)");
        }];

  } else {
    // iOS 10 notifications aren't available; fall back to iOS 8-9 notifications.
    UIUserNotificationType allNotificationTypes =
    (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
    UIUserNotificationSettings *settings =
    [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
    [application registerUserNotificationSettings:settings];
  }

  [application registerForRemoteNotifications];
  //end added for fcm notifications

  return YES;
}
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
  //
  printf("xxxxxxxxxxxxxxxxxxxx Failed to register for remote notifications with error \(error)");
}

//added for fcm notifications
// With "FirebaseAppDelegateProxyEnabled": NO
- (void)application:(UIApplication *)application
    didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//  [FIRMessaging messaging].APNSToken = deviceToken;
  printf("xxxxxxxxxxxxxxxxxxxx Received an APNs device token: \(deviceToken)");

}
//end added for fcm notifications

//
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
//  [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
//  [[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
  //added for fcm notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
//  [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
}

-(void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {

//  [[RNFirebaseMessaging instance] didReceiveRemoteNotification:response.notification.request.content.userInfo];
  completionHandler();
}
  //end added for fcm notifications

//- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
//  [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
//}
//
//- (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];
//}

  - (BOOL)application:(UIApplication *)application
              openURL:(NSURL *)url
              options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

    BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
                                                                  openURL:url
                                                        sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                               annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
                    ];
    // Add any custom logic here.
    return handled;
  }

  - (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];
  }
@end

react-native info output:

 System:
    OS: macOS 10.15.6
    CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
    Memory: 201.25 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 8.17.0 - /usr/local/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 23, 26, 27, 28
      Build Tools: 28.0.3
      System Images: android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 11.6/11E708 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: 0.61.2 => 0.61.2
  npmGlobalPackages:
    create-react-native-app: 2.0.2
    react-native-cli: 2.0.1

warning package.json: "dependencies" has dependency "@babel/runtime" with range "^7.4.3" that collides with a dependency in "devDependencies" of the same name with version "^7.6.2" warning application@0.0.1: "dependencies" has dependency "@babel/runtime" with range "^7.4.3" that collides with a dependency in "devDependencies" of the same name with version "^7.6.2" ├─ @react-native-firebase/app-types@6.7.2 ├─ @react-native-firebase/app@8.2.0 │ ├─ @react-native-firebase/app-types@6.7.2 ├─ @react-native-firebase/messaging@7.5.0


stale[bot] commented 4 years ago

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

andru1989 commented 3 years ago

@co-de did you find a solution ? I have exactly the same problem. Thanks

mikehardy commented 3 years ago

@andru1989 you may examine what an RNFBv6+ integration looks like clean by examining output of script here (with all steps shown in the script) https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh

RadoAz commented 3 years ago

I have the same issue. But... If I run app on emulator - everything fine. When creating APK file and running it on device - this error((( What can be wrong?

mikehardy commented 3 years ago

Issue title is ios. You mention android, how is that the same issue? How'd it go with the demo script?

RadoAz commented 3 years ago

Oh... Sorry... I am trying to solve this issue for 4 days... My brain destroyed........

mikehardy commented 3 years ago

I think just implementing it fresh might be easier if you were coming from v5, you've waited long enough it's like a whole new module. My demo script linked above shows every step of the integration though, with comments.