简体   繁体   中英

Flutter: Firestore component is not present

I have a problem with Firestore database under Flutter. I have done everything, what the package setup documentation says, looked into 2-3 finished public application, and tried to use the package as others use. I even tried to implement native Firestore initialization, because i think the problem is on the platform side, but still, the application get

java.lang.NullPointerException: Firestore component is not present.

when i try to use the Firestore instance.

In project/build.gradle I set

classpath 'com.google.gms:google-services:4.0.1'

for dependency and also imported

'com.google.firebase:firebase-core:16.0.1'

'com.android.support:multidex:1.0.3'

I have the google-service.json in my app folder.

Can anyone help me with this problem? I wasted a day, and still nothing. Thanks a lot!

Okay, so I figured out from looking into an other problem.

I don't know if I was the only one who didn't know, but because of a new gradle update,

classpath 'com.google.gms:google-services:3.2.1'

was deprecated. I don't really know how the hell, but this caused, that somehow Flutter didn't get the instance right, and throw a nullPointer exception. If anyone has the same problem ( debug console show some deprecated warning), you should change the

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:3.2.1'

     }
  }
}

lines in android/build.gradle to

buildscript {
    repositories {
            google()
            jcenter()
        }

    dependencies {
            classpath 'com.android.tools.build:gradle:3.3.0'
            classpath ('com.google.gms:google-services:3.2.1') {
                exclude group: 'com.google.guava', module: 'guava-jdk5'
       }
    }
}

I don't really know, why a deprecated form of dependency include caused such a problem, but this change worked for me, and I hope it helps others too. Besides that, I don't think this should cause such a wasted day, as a lot a of documentation should include this fix for the devs.

I also have the same issue after I update my cloud_functions package to 0.4.0. I tried out varies combination and I got this configuration working:

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.2.0'
    }

Note that according to the official documentation , Flutter is currently compatible with version 3.2.1 of the Google Services Plugins. I did not do a full test based on 4.2.0 of the Google Services Plugins. So far, Firebase Authentication, Cloud Functions, and Firestore work fine.

https://i.stack.imgur.com/ITWmu.png

check this once, My problem solved using this

Change the google-services to com.google.gms:google-services:3.2.1 . Although its an older version, works well with all the latest firebase extensions.

I came across this issue the other day I started working on flutter firebasebase realtime DB. Looks like it is some caching issue with flutter. After spending 50minutes to fix this issue, this comment helped me quickly resolve it.

https://github.com/flutter/flutter/issues/28745#issuecomment-480651580

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM