Firebase App is not initialised in Capacitor JS Android Build

100 views Asked by At

I have implemented Firebase Google Authentication in Capacitor JS using [@capacitor-firebase/authentication] (https://www.npmjs.com/package/@capacitor-firebase/authentication#capacitor-firebaseauthentication). It's working properly in the web app, but the application keeps crashing with the following error:

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

I have added a Google Service JSON file and also added plugins.

Android level grade:

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

App level grade:

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."
}

How to initialise firebase app as I'm using JS SDK?

Reproducible example created with minimal template

1

There are 1 answers

3
RGe On

I'm the maintainer of this plugin. This error only occurs if you do not follow the setup guide exactly. If the problem persists, please provide a Minimal, Reproducible Example using this template in a public GitHub repository so I can debug the issue.