EzDev.org

react-native-firebase

react-native-firebase - A well tested feature rich Firebase implementation for React Native, supporting both iOS & Android platforms for 10+ Firebase modules (including Cloud Firestore) ?? React Native Firebase - Simple Firebase integration for React Native a well tested feature rich firebase implementation for react native, supporting both ios & android platforms for 10+ firebase modules (including cloud firestore) ??.


What is the purpose of calling firebase.app() in react native firebase?

I tried both and all working. What are the difference?

import firebase from 'react-native-firebase';

const defaultApp = firebase.app();

defaultApp.database().ref('foobar').once('value', (snapshot) => {
  // snapshot from default app
});

vs

import firebase from 'react-native-firebase';

firebase.database().ref('foobar').once('value', (snapshot) => {
  // snapshot from default app
});

Source: (StackOverflow)

Fresh Detached Expo + RNFirebase not running on Android

long time reader, first time poster,

So I'm trying to start an app using the Detached Expokit and React Native Firebase (v3)

I made a fresh project with exp cli, followed all the instructions at https://invertase.io/react-native-firebase/ to set up ios, and it runs fine followed all the instructions to set up on android, went through some dependency hell between the expo dependencies and firebase dependencies

And now there are no more warnings, and no more errors, but when i try to run the app (either emulator or physical), it loads the js bundle to 100%, then crashes. No errors, or messages, just crash.

Ive tried everything i can think of (clean, rebuild, clear cache, reinstall npm, downgrading to RNFirebase 2x)

has anyone run into this issue before, or know how to fix? Thanks in advance


project info (ask for more if needed)

package.json:

 "dependencies": {
    "expo": "^21.0.0",
    "react": "16.0.0-alpha.12",
    "react-native": "https://github.com/expo/react-native/archive/sdk-21.0.2.tar.gz",
    "react-native-firebase": "^3.0.2"
  }

app.json:

{
  "expo": {
    "name": "xxx",
    "description": "An empty new project",
    "slug": "xxx",
    "privacy": "unlisted",
    "sdkVersion": "20.0.0",
    "version": "1.0.0",
    "orientation": "portrait",
    "primaryColor": "#cccccc",
    "icon": "./assets/icons/app-icon.png",
    "loading": {
      "icon": "./assets/icons/loading-icon.png"
    },
    "packagerOpts": {
      "assetExts": [
        "ttf",
        "mp4"
      ]
    },
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "xxx",
      "publishBundlePath": "ios/xxx/Supporting/shell-app.bundle",
      "publishManifestPath": "ios/xxx/Supporting/shell-app-manifest.json"
    },
    "android": {
      "package": "xxx"
    },
    "isDetached": true,
    "detach": {
      "scheme": "exp7d16843de771498786f3beabce0d6439",
      "iosExpoViewUrl": "https://s3.amazonaws.com/exp-exponent-view-code/ios-v1.20.5-sdk21.0.0-xxx.tar.gz",
      "androidExpoViewUrl": "https://s3.amazonaws.com/exp-exponent-view-code/android-v1.20.0-sdk21.0.0-xxx.tar.gz"
    }
  }
}

project build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    classpath 'com.google.gms:google-services:3.1.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

allprojects {
  repositories {
    mavenLocal()
    jcenter()
    maven {
      // Point to local maven repository
      url "$rootDir/../.expo-source/android/maven"
    }
    maven {
      url 'https://maven.google.com'
    }
    maven {
      url "https://jitpack.io"
    }
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

app build.gradle:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 25
  buildToolsVersion '25.0.2'

  defaultConfig {
    applicationId "xxx"
    minSdkVersion 19
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    ndk {
      abiFilters 'armeabi-v7a', 'x86'
    }
    manifestPlaceholders = [
      'appAuthRedirectScheme': 'xxx'
    ]
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  dexOptions {
    javaMaxHeapSize "8g"
  }
  packagingOptions {
    pickFirst 'META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties'
    pickFirst 'META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.xml'
    pickFirst 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
    pickFirst 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties'
    pickFirst 'META-INF/maven/com.squareup.okhttp/okhttp/pom.xml'
    pickFirst 'META-INF/maven/com.squareup.okio/okio/pom.properties'
    pickFirst 'META-INF/maven/com.squareup.okio/okio/pom.xml'
    pickFirst 'META-INF/LICENSE'
  }
}

task exponentPrebuildStep(type: Exec) {
  workingDir '../../'

  if (System.getProperty('os.name').toLowerCase().contains('windows')) {
    commandLine 'cmd', '/c', '.\\.expo-source\\android\\detach-scripts\\prepare-detached-build.bat'
  } else {
    commandLine './.expo-source/android/detach-scripts/prepare-detached-build.sh'
  }
}
preBuild.dependsOn exponentPrebuildStep

repositories{
  flatDir{
    dirs 'libs'
  }
  mavenLocal()
  maven { url 'https://maven.fabric.io/public' }
}

dependencies {
  compile(project(':react-native-firebase')) {
    // exclude group: 'com.google.android.gms'
    // exclude group: 'com.google.firebase'
    transitive = false
  }

  // RNFirebase required dependencies
  compile "com.google.firebase:firebase-core:11.4.2"

  // RNFirebase optional dependencies
  // compile "com.google.firebase:firebase-ads:11.4.2"
  // compile "com.google.firebase:firebase-auth:11.4.2"
  // compile "com.google.firebase:firebase-config:11.4.2"
  // compile "com.google.firebase:firebase-crash:11.4.2"
  compile "com.google.firebase:firebase-database:11.4.2"
  // compile "com.google.firebase:firebase-firestore:11.4.2"
  // compile "com.google.firebase:firebase-messaging:11.4.2"
  // compile "com.google.firebase:firebase-perf:11.4.2"
  // compile "com.google.firebase:firebase-storage:11.4.2"

  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile ('com.android.support:appcompat-v7:25.3.1') {
    force = true
  }
  compile ('com.android.support:recyclerview-v7:25.3.1') {
    force= true
  }
  compile ('com.android.support:animated-vector-drawable:25.3.1') {
    force= true
  }
//  compile 'com.android.support:multidex:1.0.1'


  compile('host.exp.exponent:expoview:21.0.0@aar') {
    exclude group: 'com.google.android.gms'
    exclude group: 'com.facebook.android', module: 'facebook-android-sdk'
    exclude group: 'com.facebook.android', module: 'audience-network-sdk'
    exclude group: 'io.nlopez.smartlocation', module: 'library'
    transitive = true;
  }

  compile ("com.google.android.gms:play-services-base:11.4.2") {
    force = true
  }
  compile ("com.google.android.gms:play-services-maps:11.4.2") {
    force = true
  }
  compile ('com.facebook.android:facebook-android-sdk:4.+') {
    exclude module: 'bolts-android'
  }
  compile('com.facebook.android:audience-network-sdk:4.+') {
    exclude module: 'play-services-ads'
  }
  compile('io.nlopez.smartlocation:library:3.2.11') {
    transitive = false
  }

}

apply plugin: 'com.google.gms.google-services'

mainApplication.java:

package xxx;

import android.support.multidex.MultiDexApplication;

import com.facebook.react.ReactPackage;

import java.util.Arrays;
import java.util.List;

// Needed for `react-native link`
// import com.facebook.react.ReactApplication;

// React Native Firebase
import io.invertase.firebase.RNFirebasePackage; // <-- This should be added already
// Optional packages - add as appropriate
// import io.invertase.firebase.admob.RNFirebaseAdMobPackage; //Firebase AdMob
// import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage; // Firebase Analytics
// import io.invertase.firebase.auth.RNFirebaseAuthPackage; // Firebase Auth
// import io.invertase.firebase.config.RNFirebaseRemoteConfigPackage; // Firebase Remote Config
// import io.invertase.firebase.crash.RNFirebaseCrashPackage; // Firebase Crash Reporting
import io.invertase.firebase.database.RNFirebaseDatabasePackage; // Firebase Realtime Database
// import io.invertase.firebase.firestore.RNFirebaseFirestorePackage; // Firebase Firestore
// import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; // Firebase Cloud Messaging
// import io.invertase.firebase.perf.RNFirebasePerformancePackage; // Firebase Performance
// import io.invertase.firebase.storage.RNFirebaseStoragePackage; // Firebase Storage

public class MainApplication extends MultiDexApplication {

  // Needed for `react-native link`
  public List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        // Add your own packages here!
        // TODO: add cool native modules

        // Needed for `react-native link`
        // new MainReactPackage(),
        new RNFirebasePackage(),
        // Add these packages as appropriate
        // new RNFirebaseAdMobPackage(),
        // new RNFirebaseAnalyticsPackage(),
        // new RNFirebaseAuthPackage(),
        // new RNFirebaseRemoteConfigPackage(),
        // new RNFirebaseCrashPackage(),
        new RNFirebaseDatabasePackage()
        // new RNFirebaseFirestorePackage(),
        // new RNFirebaseMessagingPackage(),
        // new RNFirebasePerformancePackage(),
        // new RNFirebaseStoragePackage()
    );
  }
}

Source: (StackOverflow)

React Native Firebase error Thread 1 SIGABRT - iOS

Problem

After following the tutorial for react-native-firebase, my app hangs after a successful build. The error I get in Xcode is: Thread 1: signal SIGABRT. I understand from other questions that this has something to do with connections, but I do not know why this error occurs.

This is my first React Native project and first time working with Xcode.

What I did

  1. I added react-native-firebase and firebase.
  2. Ran react-native link react-native-firebase.
  3. Added the GoogleService-Info.plist to the project by dragging it into the Xcode editor.
  4. Stopped all Xcode tasks and quitted Xcode.
  5. Did a pod init.
  6. Adjusted the podfile to the following:

    # Uncomment the next line to define a global platform for your project
    platform :ios, '9.0'
    
    target 'Enso' do
    # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
    # use_frameworks!
    
      # Pods for Enso
        pod 'Firebase/Core'
    
    end
    
  7. Did a pod install
  8. Opened the xcworkspace file
  9. Added the #import <Firebase.h> and [FIRApp configure]; to AppDelegate.m
  10. Cleaned the project
  11. Run the project
  12. Project build successful, but the app keeps hanging on the white screen with the name of the app and 'Powered by React Native'.
  13. After about 10 seconds the Xcode editor will show me the following: Image with error in Xcode

More info

I have these Linked Frameworks and Libraries:

  • libRNSVG.a
  • libRNBackgroundTimer.a
  • libRNFirebase.a
  • libART.a
  • libRCTBlob.a
  • libReact.a
  • libRCTAnimation.a
  • libRCTActionSheet.a
  • libRCTGeolocation.a
  • libRCTImage.a
  • libRCTLinking.a
  • libRCTNetwork.a
  • libRCTSettings.a
  • libRCTText.a
  • libRCTVibration.a
  • libRCTWebSocket.a
  • libPos-Enso.a

I have this in my Header Search Paths:

  • $(inherited)
  • $(SRCROOT)/../node_modules/react-native-background-timer/ios
  • $(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase
  • $(SRCROOT)/../node_modules/react-native-svg/ios
  • $(SRCROOT)/../ios/Pods
  • $(SRCROOT)/../node_modules/react-native/React

Source: (StackOverflow)

Could not invoke RNFirebaseFirestore.documentSet

Hi guys I add this error and I don't understand why... I'm using the starter project of react-native-firebase, and I'm trying to use firestore

enter image description here


Source: (StackOverflow)

Unable to query firestore collection on timestamp column

I have a Firestore database which contains a list of jobs in a "jobs" collection. Each job has an end date which is a "timestamp" data type. When I try to query using a where condition, I get no data back when using the react-native-firebase module.

Snapshot of data

Below is the code I'm using:

return db.collection('jobs')
    .where('end', '>=', new Date());

Also tried:

    .where('end', '>=', new Date().toISOString());

Is there a specific data type/format I must send the date value as for it to match?

When I use the standard web SDK from Firebase on my web app, the data comes back correctly.


Source: (StackOverflow)

ReactNative Firebase Firestore Crashes on Android

I'm trying to get react-native-firebase up and querying a firestore database in an android app. But whenever I try to query a collection, the app crashes with a very descriptive:

Unfortunately, RNFirebaseStarter has stopped.

This is happening right from the starter project, using the firestore query code right out of the Todo app tutorial. And is happening both in an android simulator and on a device connected through USB.

There are no errors being reported anywhere that I can find. How would I even begin to debug this?


Source: (StackOverflow)

Array of references coming null in RNFirebase

From firestore collection of document with field of type array of references is giving array of null when doing get on that collection in react-native-firebase. Where as in adminSDK and firestore npm package, the data is coming perfectly. Can any one tell what is the reason behind it. Also document having field of type reference is coming right in react-native-firebase

Expected Response

active: true,
instruments: [
    firestore.googleapis.com/project/xxxx-xxxxx/database/(default)/documents/Companies/demo/instrumentGroup/bznCmbtSzdVFdPrbAexv,
    firestore.googleapis.com/project/xxxx-xxxxx/database/(default)/documents/Companies/demo/instrumentGroup/xKMvoovwWKPc5xxjsc1K,
    firestore.googleapis.com/project/xxxx-xxxxx/database/(default)/documents/Companies/demo/instrumentGroup/FsLiNcJIyn78JTOcna4H
],
name:"Chamfer",
type:"Range",
unit:"mm"

Actual Response

active: true,
instruments: [
    null,
    null,
    null
],
name:"Chamfer",
type:"Range",
unit:"mm"

Source: (StackOverflow)

Code executes in componentDidMount but not in Other functions

So I've run into an weird issue, maybe I'm doing something wrong here but I haven't had this problem before and my app is full of similar code.

Basically I'm trying to do a simple Firestore get() in a function attached to a button onPress. For some reason the code is not run, or if it is I'm not getting any feedback. If I put the same code in componentDidMount it runs and gives me the database snapshot.

Here are the two bits of code in question.

updated for the current binding I am using

    this.usersRef = firebase.firestore().collection('users');

componentDidMount() {
    this.usersRef
        .get()
        .then((snapshot) => {
            console.log('TEST didMount snapshot', snapshot);
        }).catch((error) => {
            console.log(error)
        });
}


    submitSearch() {
        console.log('submitSearch')
        this.usersRef
            .get()
            .then((snapshot) => {
                console.log('TEST submitSearch snapshot', snapshot);
            }).catch((error) => {
                console.log(error)
            });
}

The submitSearch is called from here

            <Button style={{marginTop: 3, marginBottom: 8}} primary onPress={() => this.submitSearch()}>
                {strings.search}
            </Button>

So I've tried a lot of things here and I can't seem to figure out why the code won't work in the submitSearch function. The only thing I see from that function is the console log saying submit search.

Any ideas would be appreciated! Thanks.


Source: (StackOverflow)

Expo and react-native-firebase

I'm trying to integrate Firebase into my expo app using the react-native-firebase framework which has several advantages over the regular firebase package when it comes to react-native apps.

However, I'm running into difficulties since the instructions say I must add the GoogleService-Info.plist to ios/[YOUR APP NAME]/GoogleService-Info.plist, and expo apps don't have an ios folder from what I understand.

Am I pretty much screwed or is there a solution for this?


Source: (StackOverflow)