Skip to content

Freeze on FirebaseRemoteConfig.ActivateFetched() Unity 2017.4.6f1 Android #182

@DenizPiri

Description

@DenizPiri

When calling FirebaseRemoteConfig.ActivateFetched() at the start of the app, at first frame, the app gets stuck in launch screen image. There seem to be no apparent errors in "adb logcat" output. This normally happens with 95% chance.

Deferring the ActivateFetched call by 100ms reduces the chances of getting this launch freeze a lot. In this case, chances of freezing is around 5%.

This is how my current initialization code looks like:

Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
        {
            var dependencyStatus = task.Result;
            MainThreadDeferer.Instance.CallOnUnityThread(() =>
            {
                if (Debug.isDebugBuild)
                    Debug.LogFormat("Firebase.DependencyStatus: {0}", dependencyStatus);

                if (dependencyStatus == Firebase.DependencyStatus.Available)
                {
                    // Fetch and activate firebase remote config data.
                    Run.AfterRealtime(0.1f, () => // WARNING: Without this ActivateFetched gets stuck on Android sometimes.
                    {
                        Firebase.RemoteConfig.FirebaseRemoteConfig.ActivateFetched();
                        Firebase.RemoteConfig.FirebaseRemoteConfig.FetchAsync().ContinueWith(task2 =>
                        {
                            MainThreadDeferer.Instance.CallOnUnityThread(() =>
                            {
                                if (Debug.isDebugBuild)
                                    Debug.LogFormat("Fetched firebase remote config");
                                Firebase.RemoteConfig.FirebaseRemoteConfig.ActivateFetched();
                            });
                        });
                    });
                }
                else
                {
                    UnityEngine.Debug.LogError(System.String.Format(
                      "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
                    // Firebase Unity SDK is not safe to use here.
                }
            });
        });

MainThreadDeferer.Instance.CallOnUnityThread calls are there to defer the callbacks to main unity thread, just to make sure that task callbacks are not called in a separate thread.

Runtime I am on is Mono with .NET 2.0 Subset. Stripping level is set to "micro mscorlib". Min API level is Android 4.1, the target is Android 8.0. Building for ARMv7 arch.

I am puzzled by what might be causing the problem of being stuck. I wish firebase unity integration code was open source, would be pretty easy to understand what is going on. I assume that call is using some async API internally and waiting for the result in a while loop, just to be able to return the "bool" value. Then again, the Java API for activateFetched is not an async call. However, maybe, to get the call to the right thread, some async operation is going on there.

Would be great to get some help with this. I spent half the day battling with the error, still no clear solution. Deferring the ActivateFetched call by a constant time reduces chances of the problem happening, but doesn't fully solve it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions