I’ve created a number of apps (beginner) including Firebase, Firestore without an issue. Now I’m struggling with a new project to get the Firebase initialisation working. Running out of ideas.
Developing on Mac, Android Studio for IoS and Android.
Error:
Firebase has not been correctly initialized.
Usually this means you’ve attempted to use a Firebase service before calling Firebase.initializeApp
.`
Main
WidgetsFlutterBinding .ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
android/build.gradle (extracts)
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.gms:google-services:4.3.14"
}
android/settings.gradle
plugins {
id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
id "com.google.gms.google-services" version "4.4.0" apply false
}
app/build.gradle
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id "com.google.gms.google-services"
}
defaultConfig {
applicationId "xxx"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
pubspec
environment:
sdk: '>=3.1.4 <4.0.0'
dependencies:
flutter:
sdk: flutter
firebase_core: ^2.20.0
cupertino_icons: ^1.0.6
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.0
flutter:
uses-material-design: true`
different firebase core versions
2
Answers
In your
main.dart
‘smain
function, put this:It should be called before utilizing anything Firebase related.
Make sure to add the Firebase config plist file to the Xcode project