Firebase 应用程序未在 Capacitor JS Android Build 中初始化

问题描述 投票:0回答:1

我已经使用 @capacitor-firebase/authentication 在 Capacitor JS 中实现了 Firebase Google 身份验证。它在网络应用程序中工作正常,但应用程序不断崩溃并出现以下错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.demo.application/com.demo.application.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.demo.application. Make sure to call FirebaseApp.initializeApp(Context) first.

我添加了 Google 服务 JSON 文件,还添加了插件。

Android级别:

 dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath 'com.google.gms:google-services:4.3.15'
 }

应用级别等级:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
    implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
    implementation project(':capacitor-android')
    testImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
    implementation project(':capacitor-cordova-android-plugins')
    implementation 'com.google.firebase:firebase-core:21.1.1'
    implementation "com.google.gms:google-services:4.4.1"
}

apply from: 'capacitor.build.gradle'

try {
    def servicesJSON = file('google-services.json')
    if (servicesJSON.text) {
        apply plugin: 'com.google.gms.google-services'
    }
} catch(Exception e) {
    logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}

当我使用 JS SDK 时,如何初始化 firebase 应用程序?

android firebase google-signin capacitor capacitor-plugin
1个回答
0
投票

我是这个插件的维护者。 仅当您不严格遵循设置指南时,才会出现此错误。 如果问题仍然存在,请在公共 GitHub 存储库中使用此模板提供一个最小、可重现的示例,以便我可以调试问题。

© www.soinside.com 2019 - 2024. All rights reserved.