skip to Main Content

I added latest version of firebase dependency and initialize firebase in my flutter app but same issue happened guide someone:

Check below of my Firebase code initilize in flutter project:

void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(const MyApp());
}

check below build gradel file of app level:

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.flutter_firebase"
    compileSdk 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 {
        multiDexEnabled true
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.flutter_firebase"
        // 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 flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    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.8.1"))
    implementation("com.google.firebase:firebase-analytics")
    implementation 'com.android.support:multidex:1.0.3'

}

check below code of build gradel of project level:

buildscript {
    ext.kotlin_version = '1.9.23'

    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository
    }

    dependencies {

        // Add the Maven coordinates and latest version of the plugin
        classpath ("com.google.gms:google-services:4.4.1")
        classpath ("com.google.firebase:firebase-appdistribution-gradle:4.2.0")
        classpath ("com.google.firebase:firebase-crashlytics-gradle:2.9.9")
        classpath ("com.google.firebase:firebase-crashlytics-gradle:2.9.9")
        classpath ("com.google.firebase:perf-plugin:1.4.2")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23"
    }
}

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
}

I just want to perform basic CRUD operation in flutter with firebase.
I updated android Studio.
I updated SDK.
I added all latest dependency.
my code is run correctly but in my device showing white screen i shows you my run catalog check below:

Performing hot restart...
Syncing files to device 23076RN4BI...
Restarted application in 2,194ms.
E/flutter (28544): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(java.lang.Exception: Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly., Exception, Cause: null, Stacktrace: java.lang.Exception: Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.
E/flutter (28544):  at io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin.lambda$optionsFromResource$4$io-flutter-plugins-firebase-core-FlutterFirebaseCorePlugin(FlutterFirebaseCorePlugin.java:207)
E/flutter (28544):  at io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin$$ExternalSyntheticLambda2.run(Unknown Source:4)
E/flutter (28544):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
E/flutter (28544):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
E/flutter (28544):  at java.lang.Thread.run(Thread.java:1012)
E/flutter (28544): , null)
E/flutter (28544): #0      FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:242:7)
E/flutter (28544): <asynchronous suspension>
E/flutter (28544): #1      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter (28544): <asynchronous suspension>
E/flutter (28544): #2      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter (28544): <asynchronous suspension>
E/flutter (28544): #3      main (package:flutter_firebase/main.dart:6:3)
E/flutter (28544): <asynchronous suspension>
E/flutter (28544): 

2

Answers


  1. According to the document you need to add parameter while initializing the firebase like

    options: DefaultFirebaseOptions.currentPlatform
    
    
    Login or Signup to reply.
  2. First make sure you’ve downloaded, and imported the google-services.json file properly.

    Secondly, make sure you’ve followed steps for connecting firebase project to your flutter project.

    Official documentation: https://firebase.google.com/docs/flutter/setup?platform=android

    Important:
    In order to be able to run the "firebase" command, you have to install the Firebase CLI on your device.
    Also included in the official documentation https://firebase.google.com/docs/cli#setup_update_cli

    Workaround:
    Firebase options can be "hardcoded" but it’s not the best soultion.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search