Search code examples
cordovagoogle-cloud-firestorecordova-plugins

Can't connect to Cloud Firestore Database on Cordova app


I'm trying to build an app with Cordova where I want to connect a Google Cloud Firestore database.

I use the Cordova Firestore Plugin and followed the installation steps (add google-services.json, install dependencies etc.). To learn how the plugin is used, I build my app and connect it with Chrome DevTools to play around with the console.

When I try to get data from firestore via console like explained in the example of the plugin, I always get the following error:

Attempt to invoke virtual method 'com.google.firebase.firestore.CollectionReference com.google.firebase.firestore.FirebaseFirestore.collection(java.lang.String)' on a null object reference

I googled on that and found hints to change the version of com.google.gms:google-services to minimum 3.1.1.

What can I do?


Solution

  • Actually I faced the same issue and found a solution here:

    https://github.com/ReallySmallSoftware/cordova-plugin-firestore/issues/11#issuecomment-453435050

    By commenting out config{}: that makes both browser and android platforms work (not tested on iOS yet)

    Here the updated example:

    https://github.com/ReallySmallSoftware/cordova-plugin-firestore/issues/13#issuecomment-467531402

    var options = {
        "datePrefix": '__DATE:',
        "fieldValueDelete": "__DELETE",
        "fieldValueServerTimestamp" : "__SERVERTIMESTAMP",
        "persist": true,
    //  "config" : {}
    };