3

I'm trying to add Firebase Invites to my Unity game. I've followed all the tutorial steps and have set up seems like everything. But when I try to run the code from tutorial to send an invite, I'm getting an exception:

ApplicationException: internal::IsInitialized()
 at Firebase.FutureBase.status ()
 at Firebase.Invites.SendInviteFuture.GetTask (Firebase.Invites.SendInviteFuture fu)
 at Firebase.Invites.FirebaseInvites.SendInviteAsync (Firebase.Invites.Invite invite)
...

The code is:

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

void InitializeFirebase()
{
    Firebase.Invites.FirebaseInvites.InviteReceived += OnInviteReceived;
    Firebase.Invites.FirebaseInvites.InviteNotReceived += OnInviteNotReceived;
    Firebase.Invites.FirebaseInvites.ErrorReceived += OnErrorReceived;
}

public void ShowInviteBox(System.Action<bool> callback)
{
  var invite = new Firebase.Invites.Invite() {
    TitleText = "Invites Test App",
    MessageText = "Please try my app! It's awesome.",
    CallToActionText = "Download it for FREE",
    DeepLinkUrl = new System.Uri("http://google.com/abc")
  };
  Firebase.Invites.FirebaseInvites.SendInviteAsync(invite).ContinueWith(HandleSentInvite);
}

I use:

  • Unity 2017.3.0f3
  • Google Play Game Services Plugin for Unity 0.9.50
  • Firebase Invites 4.4.3
  • Appodeal 2.8.18 nodex
  • Game Analytics 3.10.4

Any help would be highly appreciated!

  • while implementing FirebaseAnalytics I encountered an issue on iOS that was not mentioned in the docs - I had to add the following line: FirebaseAnalytics.SetAnalyticsCollectionEnabled(true); maybe there is something similar in the Invites package that you need to call upfront? – Piotr Mar 16 '18 at 10:40
  • Thank you for trying to help! I've found so far that Appodeal plugin somehow interfers with Firebase Invites plugin (probably because of use of some google APIs of different versions). Appodeal support is trying to help to resolve the issue now. – Alex Dovgodko Mar 22 '18 at 16:49
  • Hi Alex, any luck with that? I am not using Appodeal (just Admob using the official package) and have the same error. Let me know if you managed to fix this somehow. – Piotr Apr 21 '18 at 07:50
  • Hey Piotr. After many hour spent fighting this trouble, I had to give up. With the latest version of the Firebase Invites the error looks different, but it still doesn't want to work. Guys form Appodeal support did their best to help, but with no luck. It seems, that we should direct this problem to Firebase devs. Unfortunately, I've spent too much time with this trouble atm. Should you find any solution - I'd be grateful if you could share it. – Alex Dovgodko Apr 21 '18 at 17:47
  • Alex - FYI I managed to get this all working by building an Android Studio Project. Had some troubles to get it working but finally invites do work. I believe there is something with the Android build process in Unity that missed some libraries. – Piotr Apr 23 '18 at 06:16
  • Wow! Thanks for the info! I'm building using gradle after exporting the project. The Android Studio should act the same, AFAIK. Did you use internal Unity build prior to your new solution or it was gradle? – Alex Dovgodko Apr 23 '18 at 13:27
  • Was using gradle. All compiled fine but I got the Initialization error you mentioned in this question. I moved to Android Studio. There I do not think I changed anything ... but after building in Android Studio I noticed that DeepLinks Initialization was visible somewhere in the logcat and all worked well in the app. – Piotr Apr 24 '18 at 14:38
  • Hm... I'll check that out. Thank you very much! – Alex Dovgodko Apr 24 '18 at 18:11

1 Answers1

3

I think I found a solution.

That error occurs when use "SendEvent()" before firebase initialized.

I solved error by below code.

private void InitializeFirebase()
{
    Debug.Log("FirebaseManager : Enabling data collection.");
    FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);

    Debug.Log("FirebaseManager : Set user properties.");
    // Set the user's sign up method.
    FirebaseAnalytics.SetUserProperty(
      FirebaseAnalytics.UserPropertySignUpMethod,
      "Google");
    // Set the user ID.
    FirebaseAnalytics.SetUserId("uber_user_510");
    // Set default session duration values.
    FirebaseAnalytics.SetMinimumSessionDuration(new TimeSpan(0, 0, 10));
    FirebaseAnalytics.SetSessionTimeoutDuration(new TimeSpan(0, 30, 0));

    //THIS IS SOLUTION!!!!
    Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => 
    {
        FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventLogin);
    });
}

Enter your first "SendEvent" in the CheckAndFixDependenciesAsync().

Hope this was helpful.


After I finded and installed Older version of firebase(6.15.2), The older version of firebase showed me a helpful error message...

"don't call firebase functions before check dependencies has finished"

Noname
  • 46
  • 2