【问题标题】:Flutter Default FirebaseApp is not initialized in this process com.viainno.homego. Make sure to call FirebaseApp.initializeApp(Context) firstFlutter 默认 FirebaseApp 在 com.viainno.homego 这个过程中没有初始化。确保首先调用 FirebaseApp.initializeApp(Context)
【发布时间】:2021-03-20 08:59:57
【问题描述】:

2020/12/11 更新 问题解决了。 出现问题是因为我在插件中编辑了清单。

<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>

我评论内容,然后将其迁移到我的应用清单。

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

效果很好。

问题

我每次都在 android 上收到此错误,并且我无法在我的应用中接收消息。 我已经阅读了很多关于 stackoverflow 的答案,但仍然面临这个错误。 我真的对这个错误感到困惑。 有人会帮助我吗? 非常感谢。

我在 android/app 中添加了 google-service.json enter image description here

这是我的项目级 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
}

这是我的应用级 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'

【问题讨论】:

    标签: android firebase flutter firebase-cloud-messaging


    【解决方案1】:

    您正在尝试获取 Firebase 实例而不对其进行初始化。请在尝试获取 Firebase 实例之前添加FirebaseApp.initialize()

    【讨论】:

    • 嗨!感谢您的回复。我试过这个,但我得到“Firebase 尚未正确初始化。您是否将“google-services.json”文件添加到项目中?”这真的很奇怪。
    • 当然。哪一部分?
    • 我发现如果我删除我创建的这个插件 (pub.dev/packages/tappayflutterplugin),错误就会消失。但我“必须”在我的应用中使用这个插件。
    • 很高兴你做到了!
    猜你喜欢
    • 2019-06-13
    • 1970-01-01
    • 2020-01-04
    • 2019-09-06
    • 2021-10-13
    • 2021-02-11
    • 2021-06-13
    • 2019-03-16
    • 2020-02-04
    相关资源
    最近更新 更多