Skip to content

Documentation: Can't recreate default Firebase App #890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kvanry opened this issue Oct 9, 2019 · 7 comments
Open

Documentation: Can't recreate default Firebase App #890

kvanry opened this issue Oct 9, 2019 · 7 comments
Labels

Comments

@kvanry
Copy link

kvanry commented Oct 9, 2019

Describe your environment

  • Android Studio version: 3.4.2
  • Firebase Component: Database
  • Component version: 19.1.0

Describe the problem

Caused by java.lang.IllegalStateException
FirebaseApp was deleted
com.google.android.gms.common.internal.Preconditions.checkState (Preconditions.java:9)
com.google.firebase.FirebaseApp.checkNotDeleted (FirebaseApp.java:509)
com.google.firebase.FirebaseApp.getName (FirebaseApp.java:182)
com.google.firebase.auth.internal.zzv.<init> (zzv.java:54)
com.google.firebase.auth.internal.zzas.<init> (zzas.java:6)
com.google.firebase.auth.FirebaseAuth.zzct (FirebaseAuth.java:9)
com.google.firebase.auth.FirebaseAuth.addIdTokenListener (FirebaseAuth.java:8)
com.google.firebase.database.android.AndroidAuthTokenProvider$1.addTokenChangeListener (AndroidAuthTokenProvider.java:57)
com.google.firebase.database.core.Repo.deferredInitialization (Repo.java:110)
com.google.firebase.database.core.Repo.access$000 (Repo.java:56)
com.google.firebase.database.core.Repo$1.run (Repo.java:95)
java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:458)
java.util.concurrent.FutureTask.run (FutureTask.java:266)
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run (ScheduledThreadPoolExecutor.java:301)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
java.lang.Thread.run (Thread.java:764)

And

Fatal Exception: java.lang.RuntimeException
Uncaught exception in Firebase Database runloop (3.0.0). Please report to [email protected]
com.google.firebase.database.android.AndroidPlatform$1$1.run (AndroidPlatform.java:96)
android.os.Handler.handleCallback (Handler.java:873)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loop (Looper.java:205)
android.app.ActivityThread.main (ActivityThread.java:6983)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:884)

Steps to reproduce:

We haven't been able to pinpoint how this is occuring, however our setup is we dynamically can switch between firebase environments. We've spent a few days trying to replicate, unfortunately only our customers are finding this issue.

Relevant Code:

    private fun updateFirebase(environment: Environment) {
        firebaseApp?.delete()

        when (environment) {
            Environment.Unknown,
            Environment.NotSet -> { /* We don't need to do anything here */
                return
            }
            Environment.Dev -> {
                FirebaseApp.initializeApp(context, AppConfiguration.instance.firebaseDev)
            }
            Environment.Staging -> {
                FirebaseApp.initializeApp(context, AppConfiguration.instance.firebaseStage)
            }
            Environment.Prod -> {
                FirebaseApp.initializeApp(context, AppConfiguration.instance.firebaseProd)
            }
            Environment.Europe -> {
                FirebaseApp.initializeApp(context, AppConfiguration.instance.firebaseEurope)
            }
        }
        
        FirebaseDatabase.getInstance().setPersistenceEnabled(false)
    }
@rlazo rlazo added the type: bug Something isn't working label Oct 9, 2019
@rlazo
Copy link
Collaborator

rlazo commented Oct 11, 2019

/cc @schmidt-sebastian

@kvanry
Copy link
Author

kvanry commented Oct 17, 2019

In the meantime is there anything we can do to mitigate this issue as it's affecting a large percentage of our users?

@schmidt-sebastian
Copy link
Contributor

@kvanry Sorry for not getting back to you earlier.

It looks like you are deleting the default app and attempting to replace it with a new FirebaeApp. To do this properly, you will have to manually pass in the new app into the FirebaseDatabase.getInstance() call (getInstance() will become getInstance(app)).

Can you try this? I believe your error should then go away.

@kvanry
Copy link
Author

kvanry commented Oct 17, 2019

I mean, yes we can try this, that being said if that is the fix, I feel like it should be more clear that if you delete the default app that this is necessary, either in documentation or if the error that is thrown could be more descriptive. Otherwise the assumption is that the new default app becomes the new FirebaseApp instance.

@schmidt-sebastian schmidt-sebastian added api: core and removed api: database type: bug Something isn't working labels Oct 18, 2019
@schmidt-sebastian schmidt-sebastian changed the title Fatal Exception: java.lang.RuntimeException Uncaught exception in Firebase Database runloop (3.0.0). Please report to [email protected] Documentation: Can't recreate default Firebase App Oct 18, 2019
@schmidt-sebastian
Copy link
Contributor

Moving this to the core component to get the docs fixed.

@ashwinraghav
Copy link
Contributor

This has an explanation of why it is tricky to implement delete effectively
#66 (comment)

@ashwinraghav
Copy link
Contributor

Just wanted to drop a note that our efforts are generally focussed only on APIs that are publicly documented. The delete API is currently not supported for these sorts of reasons.

I'll leave this open as a feature request though.

https://github.com/firebase/firebase-android-sdk/blob/master/firebase-common/src/main/java/com/google/firebase/FirebaseApp.java#L308-L315

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants