Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make sure to call FirebaseApp.initializeApp(Context) first. Default FirebaseApp is not initialized in this process com.example.login

I am making a Firebase Authentication Signup Page using kotlin and there is a run time error while I am running the app. Please See the 3rd and 14th line I can't figure out what is the problem.

I didnt attach the main code please inform me if the codes are necessary to attach.

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.login, PID: 7505
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.login/com.example.login.Register}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.login. Make sure to call FirebaseApp.initializeApp(Context) first.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.login. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
        at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
        at com.example.login.Register.<init>(Register.kt:15)
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6119) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
Application terminated.

Implementation

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:16.0.3'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
like image 818
Lenin Bakhara Avatar asked Apr 16 '19 13:04

Lenin Bakhara


3 Answers

I had something similar because I forgot about adding

apply plugin: 'com.google.gms.google-services'

on bottom of build.gradle

like image 71
Rafols Avatar answered Nov 08 '22 12:11

Rafols


Thanks everyone but I solved it myself. All I did is

classpath 'com.google.gms:google-services:4.1.0'

to

classpath 'com.google.gms:google-services:4.2.0'

That worked for me!

like image 24
Lenin Bakhara Avatar answered Nov 08 '22 12:11

Lenin Bakhara


Instead of adding below the line in project-level build.gradle, add it into the app level gradle.

apply plugin: 'com.google.gms.google-services'

like image 1
Maya Mohite Avatar answered Nov 08 '22 11:11

Maya Mohite