Im trying to connect my flutter project in firebase but I keep getting this error
Launching libmain.dart on sdk gphone x86 in debug mode…
Running Gradle task ‘assembleDebug’…
√ Built buildappoutputsflutter-apkapp-debug.apk.
Installing buildappoutputsflutter-apkapp-debug.apk…
Debug service listening on ws://127.0.0.1:54542/CBgATS3doF8=/ws
Syncing files to device sdk gphone x86…
E/flutter (15791): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null)
E/flutter (15791): #0 FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)
E/flutter (15791): <asynchronous suspension>
E/flutter (15791): #1 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter (15791): <asynchronous suspension>
E/flutter (15791): #2 Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter (15791): <asynchronous suspension>
E/flutter (15791): #3 main (package:database/main.dart:5:3)
E/flutter (15791): <asynchronous suspension>
E/flutter (15791):
I did many tutorials in youtube but most of them are outdated most of the syntax change but even i find an updated tutorial this is always the case. I follow the steps in adding android in the firebase website
this is my androidbuild.gradle
buildscript {
ext.kotlin_version = '1.9.10'
repositories {
google()
mavenCentral()
}
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.4.0'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
this is my appbuild.gradle
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id 'com.google.gms.google-services'
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
namespace "com.example.database"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.database"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:32.4.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.android.support:multidex:1.0.3'
}
2
Answers
I changed the version of the classpath 'com.google.gms:google-services:4.4.0' to classpath 'com.google.gms:google-services:4.3.15'. It works I don't know why but I don't get the errors
The error you’re encountering seems to be related to Firebase initialization in your Flutter app. The error message mentions that the platform returned a null value for a non-null return value when initializing Firebase. This error can occur for various reasons, but it’s usually related to incorrect configuration or dependencies.
Here are some steps you can take to troubleshoot and potentially resolve the issue:
Check your Firebase configuration:
Verify that you have downloaded the google-services.json file for Android and placed it in the correct location in your Flutter project (usually in the android/app directory).
Verify your Firebase dependencies:
Ensure that you have the correct versions of Firebase and Google Play services dependencies in your app-level build.gradle file (usually located at android/app/build.gradle). You can find the correct versions on the Firebase documentation.