Flutter FirebaseException (core/not-initialized exception

Viewed 9098

When I run my app I get the following:

FirebaseException ([core/not-initialized] Firebase has not been correctly initialized. Have you added the "google-services.json" file to the project? View the Android Installation documentation for more information: https://firebaseextended.github.io/flutterfire/docs/installation/android)

I am 100% certain that I copy and pasted my "google-services.json" file in the correct directory:

android > app

EDIT: This is my main.dart looks like*******************

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // Create the initialization Future outside of `build`:
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      // Initialize FlutterFire:
      future: _initialization,
      builder: (context, snapshot) {
        // Check for errors
        if (snapshot.hasError) {
          return Center(
            child: Text("Someting went Worng"),
          );
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
          return StreamProvider<SignedInUser>.value(
            value: AuthService().user,
            child: MaterialApp(
              home: Wrapper(),
            ),
          );
        }

        // Otherwise, show something whilst waiting for initialization to complete
        return CircularProgressIndicator();
      },
    );
  }
}

please help!

Thank you in advance!

3 Answers

Ok guys, After spending hours on trying to find ways to figure this issue out, I finally SOLVED it!

So, looks like I didn't properly configure my gradle files in the android folder. This is very important (obviously)! I was missing apply plugin: 'com.google.gms.google-services' Then of course I was paranoid and decided to open the project in android studio and let studio help me update all the versions to the latest and greatest (I would be weary of this, some of these versions are not 100% stable)

Once I fixed that, I was faced with another issue...

"Cannot start daemon... etc", it looks like my environment was pointing to the wrong java folder. It was pointing to the x86/java JRE folder. This is wrong! Make sure you are pointing to the JDK folder.

Once I fixed those issues, my flutter app was working again.

I hope this helps someone in the future!

Good luck and happy programming!

You should follow Firebase's Android Installation guide, which lists:

  • Once your Android app has been registered, download the configuration file from the Firebase Console (the file is called google-services.json). Add this file into the android/app directory within your Flutter project.

  • Add classpath 'com.google.gms:google-services:4.3.8' to android/build.gradle

  • Add apply plugin: 'com.google.gms.google-services' to android/app/build.gradle

just for information for who still with the same problem and not solved. you can try to insert this code in Build.gradle\app

rootProject.ext { set('FlutterFire', [ FirebaseSDKVersion: '25.12.0' ]) }

And don't forget to insert this code in pubspec.yaml

firebase_core: "^0.5.2"

Related