flutter firebase MissingPluginException - firebase

I just added firebase to my flutter App, i followed all the steps correctly, but i'm getting an error when initializing the app
this is my code to initialize app
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: new ThemeData(
canvasColor: Colors.white,
),
home: PersistentTabsDemo(),
onGenerateRoute: route.controller,
);
}
}
this are the dependecies i added to pubsec.yaml
firebase_core: ^1.6.0
firebase_analytics: ^8.3.1
firebase_auth: ^3.1.0
cloud_firestore: ^2.5.1
and this is the error
Error: MissingPluginException(No implementation found for method Firebase#initializeCore on channel
plugins.flutter.io/firebase_core)
Edit: i tried removing async and await from my main class now i'm getting new error
No firebase App 'default' has been created - call Firebase.intializeApp()

Try
Flutter clean
Pub.get
If these two doesn't work
Something is missing in setup of Firebase flutter

If anyone else had the same issue as me
I've fixed the issue by creating another project and added the sh1 and sh256 to firebase
just follow this tuto it's really helpful https://www.youtube.com/watch?v=CpyALC8Zpxo
PS: when u add firebase to your flutter project don't run it on chrome debug you will get an error, run it on your emulator or smartphone
happy coding ^^

Related

flutterfire crashlytics not enable

not enable crashlyrics in firebase console, after
await Firebase.initializeApp();
FirebaseCrashlytics.instance.crash();
my code
Future<void> main() async {
//runZonedGuarded<Future<void>>(() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
FirebaseCrashlytics.instance.crash();//this i also set in initState and build
runApp(const MyApp());
//}, (error, stack) => FirebaseCrashlytics.instance.recordError(error, stack));
}
app/build.gradle:
implementation platform('com.google.firebase:firebase-bom:29.0.4')
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-crashlytics-ktx'
android/build.gradle:
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
Tried start app with flutter run --release
also I tried use this example with my options: DefaultFirebaseOptions.currentPlatform: https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_crashlytics/firebase_crashlytics/example/lib/main.dart
I did everything according to the instructions from here https://firebase.flutter.dev/docs/ Getting started and Craslytics
don't have any errors, except for crashlytics not working in the firebase console
The problem was solved by another device, with android 11, with it there was a log about the request for crashlytics
There was no request on my device with 12 android, so far I will put the issue resolved, although I would like to have a solution to the problem for 12 android

How Firebase Works Internally on Flutter Dependencies

Currently, I use Firebase in the Flutter project. Firebase Analytics library in detail.
However, I became curious when I used this library.
Firebase Analytics's services operate automatically without any method calls from the entry point.
All I have to do is add the dependencies of the project as follows:
dependencies:
firebase_analytics: ^8.3.1
I don't know what procedures this is internally activated and moved by.
Can any experts explain how this is possible internally?
Firebase Analytics's services operate automatically without any method
calls from the entry point.
All I have to do is add the dependencies of the project:
dependencies:
firebase_analytics: ^8.3.1
That is not correct as there are a couple more processes to set it up.
Here is the step from the package's documentation:
To use this plugin, add firebase_analytics as a dependency in your pubspec.yaml file.
You must also configure firebase analytics for each platform project: Android and iOS.
You need to add the FirebaseAnalytics object and the FirebaseAnalyticsObserver object to the MaterialApp:
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static FirebaseAnalytics analytics = FirebaseAnalytics();
static FirebaseAnalyticsObserver observer =
FirebaseAnalyticsObserver(analytics: analytics);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Firebase Analytics Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
navigatorObservers: <NavigatorObserver>[observer],
home: MyHomePage(
title: 'Firebase Analytics Demo',
analytics: analytics,
observer: observer,
),
);
}
}
The FirebaseAnalyticsObserver creates a NavigatorObserver that sends events to FirebaseAnalytics.

Flutter app error message: No Firebase App

I recently went back to a Flutter project I've not touched for a couple of months and updated a few bits and pieces. Now, when I run the app in my emulator, I get the message:
[core/no-app] No Firebase App '[DEFAULT]' has been created
I added this line of code to initialize it in the app: await Firebase.initializeApp();... but it now doesn't appear to connect to my Firebase, just an empty one that I presume it has created on the fly.
This was my original code, which according to this site is the correct way to initialize the app: https://firebase.flutter.dev/docs/overview/
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
final Future<FirebaseApp> _initialization = Firebase.initializeApp();
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
home: FutureBuilder(
future: _initialization,
builder: (context, snapshot) {...
Any idea what I'm doing wrong? The original app on my phone works fine with Firebase, so I presume it's something to do with updating Flutter, Firebase to the latest versions.
Thanks
You should initalize your app in the main function before you run your app, not in the MyApp widget.
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(); // add this line
runApp(MyApp());
}
Ah, it wasn't anything to do with the incorrect Firebase app. I did initialize it in the main function, but in debugging I found that it was hitting an error in reading an object from the database. It was just incorrectly defined. I fixed that and it works now.
Thanks

MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) on release

I'm building an flutter app with Firebase auth. When I'm testing with flutter run at my android emulator or my android phone the app runs pretty well without major errors.
The problem happens when I try to build an apk or an appbundle and Firebase.initializeApp() fail.
Since I'm not running in debug mode I'm not sure how to trace this error.
[UPDATE]
I could trace the error catching the exception thrown from Firebase.initializeApp() and was MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core)
I still couldn't figured out why this error just appears on release while on debug runs perfectly.
Here is my app/build.gradle snippet
(...)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
(...)
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:26.2.0')
implementation 'com.google.firebase:firebase-dynamic-links'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
}
And my project build.gradle dependecies
(...)
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.4'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.9, 0.99.99]'
}
(...)
And my firebase dependencies
dependencies:
flutter:
sdk: flutter
firebase_core: ^0.7.0
cloud_firestore: ^0.16.0
firebase_auth: ^0.20.0+1
firebase_storage: ^7.0.0
I was facing the same issue so what I did was in my main.dart file I just added this code and it worked out for me. What it does is if Firebase.intitalizeApp() fails then it will show an errorPage which i have created and if it loads then it can show the application home page and if it is still loading then it shows a loading page. Here is the code for it. Hope it helps you worked for me.
#override
Widget build(BuildContext context) {
return FutureBuilder(
// Initialize FlutterFire
future: Firebase.initializeApp(),
builder: (context, snapshot) {
// Check for errors
if (snapshot.hasError) {
return SomethingWentWrong();
}
// Show Application
if (snapshot.connectionState == ConnectionState.done) {
return StreamProvider<Help4YouUser>.value(
value: AuthService().user,
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Wrapper(),
),
);
}
// Initialization
return PouringHourGlassPageLoad();
},
);
}

Flutter + Firebase | java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist

I am trying to complete a very simple exercise by connecting my basic Flutter app to Cloud Firestore (in Firebase).
I have followed the instructions with regards to setup. However, I am getting the following error.
E/MethodChannel#plugins.flutter.io/cloud_firestore(13217): Failed to handle method call
E/MethodChannel#plugins.flutter.io/cloud_firestore(13217): java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
My flutter code:
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Playground',
home: Scaffold(
appBar: AppBar(
title: Text('Playground App'),
),
body: Column(children: <Widget>[
Text('Sup World?'),
StreamBuilder(
stream: Firestore.instance.collection('test').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text('Loading....');
return Text('Loaded');
},
)
])));
}
}
Dependencies in the android\build.gradle file
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.0.1'
}
Dependencies and new lines added in the android\app\build.gradle file
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
Dependencies in the pubspec.yaml
dependencies:
flutter:
sdk: flutter
intl: 0.15.7
cloud_firestore: ^0.8.2
I've also downloaded and added the google-services.json file to the android\app folder.
In the Firestore db, I have a collection with id test containing one document.
Expected result:
The text "Loaded" should appear under the text "Sup World?"
However, I am getting the above error and it's showing the text "Loading".
Could someone help in getting this resolved please?
I had posted this on GitHub as well. Running flutter clean on the project and then running the app again fixed it for me.
The url to the GitHub issue.
https://github.com/flutter/flutter/issues/28003
I got this error when I updated to newer google-services.
Switched back to classpath 'com.google.gms:google-services:3.2.1' and it started working fine.

Resources