Re: [Firebase] FirebaseAuth in application class and Firebase crash reporting exception

901 views
Skip to first unread message

Samuel Stern

unread,
Jul 14, 2016, 1:16:13 PM7/14/16
to Firebase Google Group
This error is happening because FIrebase Crash reporting adds a second process to your app (so it can catch crashes in the main process).  This means your Application onCreate method is being called twice.  However FirebaseApp is initialized by the FirebaseInitProvider ContentProvider, which has a different lifecycle.

I would strongly suggest not doing authentication in your Application class, but if you really need to you can avoid this error by checking FirebaseApp has been initialized using FirebaseApp.getApps().size() before making the call to FirebaseAuth.getInstance(), which implicitly calls FirebaseApp.getInstance().

- Sam

On Wed, Jul 13, 2016 at 8:51 PM Eoin Fogarty <eoinf...@gmail.com> wrote:
If I have a class that extends Application. And I try to sign in anonymously

public class MainApplication extends Application {
   
   
@Override
    public void onCreate() {
       
super.onCreate();

       
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
        firebaseAuth
.signInAnonymously().addOnCompleteListener(task -> {
           
if (task.isSuccessful()) {
               
Log.d("MainApplication", "SignInAnonymously");
           
}
       
});
   
}
}

And at the same time I am trying to use firebase crash reporting. 

compile 'com.google.firebase:firebase-crash:9.2.1'

I encounter this crash.

Process: com.redstar.collectors:background_crash, PID: 30555
java.lang.RuntimeException: Unable to create application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4612)
    at android.app.ActivityThread.access$1600(ActivityThread.java:169)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5476)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. 
    at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
    at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
    at com.redstar.collectors.MainApplication.onCreate(MainApplication.java:22)
    at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:369)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4609)
    at android.app.ActivityThread.access$1600(ActivityThread.java:169) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5476) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
    at dalvik.system.NativeStart.main(Native Method) 

If I dont use crash reporting there is no exception.
If I move the sign in code into an activity class it seems to work ok.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/c742b563-883f-4dff-a794-a767f3181b04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Prakash Joshi

unread,
Aug 9, 2016, 3:18:26 PM8/9/16
to Firebase Google Group
Right this is still in Beta, and this is Known Issue: https://firebase.google.com/docs/crash/android#known-issues

Thought to share to check if there is change in known issues in future!
Reply all
Reply to author
Forward
0 new messages