Flutter Default FirebaseApp is not initialized in this process com.viainno.homego. Make sure to call FirebaseApp.initializeApp(Context) first

2,595

You're trying to get an instance of Firebase without initialize it. Please add FirebaseApp.initialize() before you try to get an instance of Firebase.

Share:
2,595
Tung
Author by

Tung

Updated on December 26, 2022

Comments

  • Tung
    Tung over 1 year

    Update 2020/12/11 The problem solved. The problem occurs because i edit the manifest in the plugin.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tungwang.tappayflutterplugin">
    
    <!--    <application-->
    <!--        xmlns:tools="http://schemas.android.com/tools"-->
    <!--        tools:node="replace"-->
    <!--        />-->
    
    </manifest>
    

    I comment the content then migrate it to my app's manifest.

    <application
            android:name=".Application"
            android:label="Home Go"
            android:icon="@drawable/app_icon"
            xmlns:tools="http://schemas.android.com/tools"
            tools:replace="android:label">
    

    It works perfectly.

    Problem

    I got this error on android every time, and i can't receive message in my app. I've read many answers on stackoverflow, but still facing this error. I am really confused on this error. Would anybody help me? Thank a lot.

    I added google-service.json in android/app enter image description here

    This is my project level build.gradle.

    buildscript {
        ext.kotlin_version = '1.3.50'
        repositories {
            google()
            jcenter()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    
            //FCM
            // Add the google services classpath
            classpath 'com.google.gms:google-services:4.3.2'
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    This is my app level build.gradle.

    def localProperties = new Properties()
    def localPropertiesFile = rootProject.file('local.properties')
    if (localPropertiesFile.exists()) {
        localPropertiesFile.withReader('UTF-8') { reader ->
            localProperties.load(reader)
        }
    }
    
    def flutterRoot = localProperties.getProperty('flutter.sdk')
    if (flutterRoot == null) {
        throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
    }
    
    def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
    if (flutterVersionCode == null) {
        flutterVersionCode = '1'
    }
    
    def flutterVersionName = localProperties.getProperty('flutter.versionName')
    if (flutterVersionName == null) {
        flutterVersionName = '1.0'
    }
    
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    
    android {
        compileSdkVersion 28
    
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
    
        lintOptions {
            disable 'InvalidPackage'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.viainno.homego"
            minSdkVersion 18
            targetSdkVersion 29
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test:runner:1.1.1'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
        implementation 'com.google.firebase:firebase-messaging:20.2.4'
        implementation 'com.android.support:multidex:1.0.3'
    }
    
    //FCM
    // ADD THIS AT THE BOTTOM
    apply plugin: 'com.google.gms.google-services'
    
  • Tung
    Tung over 3 years
    Hi! Thanks for your reply. I've try this, but i got "Firebase has not been correctly initialized. Have you added the "google-services.json" file to the project?" This is really strange.
  • Tung
    Tung over 3 years
    Sure. Which part?
  • Tung
    Tung over 3 years
    I found if i remove this plugin (pub.dev/packages/tappayflutterplugin) which i create, the error disappear. But i "have to" use this plugin in my app.
  • Javad Moradi
    Javad Moradi over 3 years
    Glad you did it!