我已经使用 @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 应用程序?