[FR]: Public API to fully shut down Firebase (FirebaseHandler) when using Unity as a Library / Application.Unload
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start by tracing FirebaseHandler initialization and termination in the Firebase.Platform runtime, then review how FirebaseApp and the Unity synchronization context are managed during Unity as a Library unload. Define a supported public shutdown and reinitialization lifecycle for named apps, including what callers must do before Application.Unload(). Done means the public API and lifecycle documentation cover clean reinitialization in the same process.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
We embed our Unity app inside a native host app using Unity as a Library (iOS and Android).
The user can open the Unity part, close it, and open it again during the same process lifetime.
When the user closes it, we unload the Unity player and load it again later.
We use Firebase App, Auth, Firestore and App Check, all with a named FirebaseApp
(FirebaseApp.Create(options, name)). We do this because the host app may use Firebase itself.
The problem: even after we dispose every public Firebase object, the static
Firebase.Platform.FirebaseHandler stays alive after the Unity unload. On the next launch of the
Unity part, the "Firebase Services" GameObject (and its UnitySynchronizationContext) is not
created again, because the SDK still thinks it is initialized. After that, callbacks such as
ContinueWithOnMainThread and Firestore listeners no longer work as expected.
Current workaround (reflection)
The only way we found to make re-initialization work is to call FirebaseHandler.Terminate()
through reflection before the "Firebase Services" GameObject is destroyed:
_firebaseAuth.Dispose();
_firebaseApp.Dispose();
// FirebaseHandler survives Application.Unload and prevents "Firebase Services"
// from being recreated on the next launch. Must be called before
// "Firebase Services" is destroyed so its UnitySynchronizationContext is reset too.
Type.GetType("Firebase.Platform.FirebaseHandler, Firebase.Platform")
?.GetMethod("Terminate", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)
?.Invoke(null, null);
We also have to add a link.xml so that IL2CPP managed code stripping keeps this method:
<linker>
<assembly fullname="Firebase.Platform">
<type fullname="Firebase.Platform.FirebaseHandler" preserve="all"/>
</assembly>
</linker>
This works, but it is fragile. It depends on an internal type and method name that can change
in any release without notice, and it has to be kept safe from code stripping by hand.
Steps to reproduce (without the workaround)
- Embed a Unity project using Firebase (App + Auth + Firestore) in a native app (Unity as a Library).
- Launch the Unity part, create a named
FirebaseApp, sign in anonymously, listen to a Firestore document. - Dispose
FirebaseAuth/FirebaseApp, then unload Unity (Application.Unload()/requestSelfUnload()). - Launch the Unity part again from the host app and initialize Firebase again.
- Observe that
"Firebase Services"is not recreated and that main-thread continuations / listeners do not fire.
Environment
- Firebase Unity SDK: 13.13.0 (App, Auth, Firestore, App Check, via UPM .tgz)
- Unity version: 6000.3.14
API Proposal
A supported, public way to fully shut down the Firebase Unity runtime so that it can be
initialized again cleanly in the same process. For example:
FirebaseApp.TerminateAll()/FirebaseApp.Shutdown(), which disposes all apps and resets
FirebaseHandler, the"Firebase Services"GameObject and the synchronization context; or- making
FirebaseHandler.Terminate()(or an equivalent) public inFirebase.Platform.
It would help if the docs also described the expected lifecycle for Unity as a Library:
what to call before Application.Unload(), and whether re-initialization in the same process
is supported
Firebase Product(s)
Firestore
Targeted Platform(s)
Android, Apple Platforms
- Lingua principale
- C#
- Stelle
- 325
- Fork
- 62
- Merge medio
- 1g 17h
- PR unite (30g)
- 13
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di firebase/firebase-unity-sdk
-
[Bug] Desktop managed DLLs marked Required32Bit fail to load on ARM64 CoreCLR (Unity 7 alpha)Forse già presa @AustinBenoit l’ha presa oggi. Apertaapi: core desktop production type: bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
firebase/firebase-unity-sdk#1566 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
api: core
Difficoltà 4/5 3-5 giorni Idoneità per principianti 43/100
firebase/firebase-unity-sdk#1562 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
api: crashlytics type: question
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
firebase/firebase-unity-sdk#1560 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] App Check (iOS): crash in TokenChangedMethod because AppCheckToken.expire_time_millis is left uninitializedForse già presa @AustinBenoit l’ha presa 7 giorni fa. Apertaapi: appcheck type: bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
firebase/firebase-unity-sdk#1556 · 6 commenti · 1 reazione · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
api: appcheck desktop production type: bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
firebase/firebase-unity-sdk#1530 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di firebase/firebase-unity-sdk
Issue simili
-
Support Flux ignore rules (drift detection ignore paths) in Microsoft.KubernetesConfiguration schemaAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
Azure/azure-resource-manager-schemas#3921 ·
I maintainer di solito rispondono entro 1 giorno
-
text-align: justify is ignored in HTML to PDF conversionForse già presa @PrzemyslawKlys l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
I maintainer di solito rispondono entro 4 giorni
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100