Skip to content
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

[Bug] Don't call Firebase functions before CheckDependencies has finished #1075

Open
WiseKodama opened this issue Jul 22, 2024 · 6 comments
Open

Comments

@WiseKodama
Copy link

Description

          Non-fatal Exception: java.lang.Exception: InvalidOperationException : Don't call Firebase functions before CheckDependencies has finished
       at Firebase.FirebaseApp.ThrowIfCheckDependenciesRunning(Firebase.FirebaseApp)
       at Firebase.FirebaseApp.GetInstance(Firebase.FirebaseApp)
       at Firebase.FirebaseApp.get_DefaultInstance(Firebase.FirebaseApp)
       at Firebase.Analytics.FirebaseAnalytics..cctor(Firebase.Analytics.FirebaseAnalytics.)

Why is this a thing? Why is accessing Static fields(FirebaseAnalytics.EventScreenView and FirebaseAnalytics.ParametersScreenName) an issue?
We had an issue where RemoteConfig did not work if Firebase functions were called before CheckDependencies finished, however I have no info if this is happening to these users...

Please remove this exception and ensure that it works normally even if a FirebaseFunction is called.

Reproducing the issue

This is happening to our live users and reported through Crashlytics, so repocase is not known.
I would assume a slow device should produce this...

Firebase Unity SDK Version

11.7.0

Unity editor version

2022.3.38f1

Installation Method

.unitypackage

Problematic Firebase Component(s)

Analytics

Other Firebase Component(s) in use

Crashlytics, Remote Config

Additional SDKs you are using

AppLovin MAX, Qonversion

Targeted Platform(s)

Android

Unity editor platform

Windows

Scripting Runtime

IL2CPP

Release Distribution Type

Pre-built SDK from https://firebase.google.com/download/unity

Relevant Log Output

Non-fatal Exception: java.lang.Exception: InvalidOperationException : Don't call Firebase functions before CheckDependencies has finished
       at Firebase.FirebaseApp.ThrowIfCheckDependenciesRunning(Firebase.FirebaseApp)
       at Firebase.FirebaseApp.GetInstance(Firebase.FirebaseApp)
       at Firebase.FirebaseApp.get_DefaultInstance(Firebase.FirebaseApp)
       at Firebase.Analytics.FirebaseAnalytics..cctor(Firebase.Analytics.FirebaseAnalytics.)

If using CocoaPods for Apple platforms, the project's Podfile.lock

Expand Podfile.lock snippet
👀 Replace this line with the contents of your Podfile.lock!
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@argzdev
Copy link

argzdev commented Jul 24, 2024

Hi @WiseKodama, thanks for reaching out. The Firebase SDK checks to make sure that all the necessary dependencies are included before it runs.

Do you have the condition checker of CheckAndFixDependenciesAsync before running any Firebase calls?

protected virtual void Start() {
      FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
        dependencyStatus = task.Result;
        if (dependencyStatus == DependencyStatus.Available) {
          InitializeFirebase();
        } else {
          Debug.LogError(
            "Could not resolve all Firebase dependencies: " + dependencyStatus);
        }
      });
    }

You can take a look into our Firebase Unity Quickstart for reference. It'll help guide you in configuring your project correctly.

Let me know if that helps. Thanks!

@argzdev argzdev added the needs-info Need information for the developer label Jul 24, 2024
@WiseKodama
Copy link
Author

I do but more complex projects do not work that way.
Sometimes you want to sent analytics event at app start, currently I create a queue and send them off once Firebase dependency checker is done.
However the issue is that to queue a specific event that uses for example FirebaseAnalytics.EventScreenView will call the constructor on FirebaseAnalytics resulting in the error above.
Why doesn't firebase have a built in queuing system?
It seems counter productive that static fields throw this error, should we really have a check infront of every static field accessor relating to Firebase?

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Jul 24, 2024
@argzdev
Copy link

argzdev commented Jul 24, 2024

I understand and sorry for the issue you're experiencing right now. Unfortunately, the current design does not allow any calls prior to the CheckAndFixDependenciesAsync. I know this is not ideal, and this is something we're still trying to work on.

There were also previous discussions of this in the quickstart. I did see an alternative posted by one of the developers, however I haven't tried it myself.

For now, I'll mark this as a feature request, and bring this up to our engineers to see if we have updates or future plans. However, please note that we currently don't have a timeline for this. I'll reply back here once we receive feedback. Thanks!

@KrazeyKami
Copy link

KrazeyKami commented Sep 21, 2024

I fixed this as follows;
For every time I need to send something to Firebase (e.g. an Event), I wrote a function and passed the eventcall in this function, like so:

  • First, write the function that accepts a string as the input:
 public static void CheckIfReady(string message)
 {

     Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
         Firebase.DependencyStatus dependencyStatus = task.Result;
         if (dependencyStatus == Firebase.DependencyStatus.Available)
         {
             Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance;
             Debug.Log("Firebase is ready for use.");
             FirebaseAnalytics.LogEvent(message);
         }
         else
         {
             UnityEngine.Debug.LogError(System.String.Format(
               "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
         }
     });
 }
  • Then, you can call this function with the input event, like so:

CheckIfReady("Your LogEvent goes here...");

C'est Ça, no more errors.

@WiseKodama
Copy link
Author

WiseKodama commented Sep 21, 2024 via email

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

No branches or pull requests

4 participants