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

Custom config provided in code isn't recognized #55

Closed
cado1982 opened this issue Sep 20, 2021 · 3 comments
Closed

Custom config provided in code isn't recognized #55

cado1982 opened this issue Sep 20, 2021 · 3 comments
Labels
api: analytics api: core closed-by-bot needs-info Need information for the developer stale Don't have recent activity type: question

Comments

@cado1982
Copy link

cado1982 commented Sep 20, 2021

I'm attempting to provide Firebase config using FirebaseApp.Create but Analytics is logging errors that it can't find the google_app_id.

public class FirebaseAnalyticsManager : MonoBehaviour
{
    private void Awake()
    {
        InitializeFirebase();
    }

    private void InitializeFirebase()
    {
        Debug.Log("Initializing Firebase");

#if PRODUCTION
        SetProductionEnvironment();
#else
        SetDevelopmentEnvironment();
#endif

#if UNITY_IOS || UNITY_ANDROID
        FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
        {
            var dependencyStatus = task.Result;

            if (dependencyStatus == Firebase.DependencyStatus.Available)
            {
                Debug.Log("Firebase available");
                OnFirebaseAvailable();
            }
            else
            {
                Application.Quit();      
            }
        }); 
#endif
    }

    private void OnFirebaseAvailable()
    {
#if UNITY_IOS || UNITY_ANDROID
        FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
        SetupMessaging();
#endif
    }

    private static FirebaseApp SetDevelopmentEnvironment()
    {
        Debug.Log("Setting Development environment");
        AppOptions options = new AppOptions();
        options.ProjectId = "######";
        options.StorageBucket = "######.appspot.com";
        options.AppId = "######";
        options.ApiKey = "######";
        options.MessageSenderId = "######";
        options.DatabaseUrl = null;
        return FirebaseApp.Create(options);
    }

    private static FirebaseApp SetProductionEnvironment()
    {
        Debug.Log("Setting Production environment");
        AppOptions options = new AppOptions();
        options.ProjectId = "######";
        options.StorageBucket = "######.appspot.com";
        options.AppId = "######";
        options.ApiKey = "######";
        options.MessageSenderId = "######";
        options.DatabaseUrl = null;
        return FirebaseApp.Create(options);
    }
}

Running on an Android device provides the following logs from logcat

2021/09/20 20:08:29.429 24721 24867 Info Unity Initializing Firebase
2021/09/20 20:08:29.429 24721 24867 Info Unity Setting Production environment
2021/09/20 20:08:29.577 24721 24867 Info FirebaseApp Device unlocked: initializing all Firebase APIs for app [DEFAULT]
2021/09/20 20:08:29.658 24721 24867 Info FirebaseCrashlytics Initializing Firebase Crashlytics 18.0.1 for com.evenlycoolergames.biomesqa
2021/09/20 20:08:29.759 24721 24867 Info firebase Firebase Analytics API Initializing
2021/09/20 20:08:29.761 24721 24867 Info firebase analytics API Initialized
2021/09/20 20:08:29.792 24721 24867 Info firebase Firebase Cloud Messaging API Initialized
2021/09/20 20:08:29.844 24721 25288 Info Unity Firebase available
2021/09/20 20:08:30.016 24721 24867 Info Unity Firebase Analytics API Initializing
2021/09/20 20:08:30.017 24721 24867 Info Unity analytics API Initialized
2021/09/20 20:08:30.018 24721 24867 Info Unity Firebase Cloud Messaging API Initialized
2021/09/20 20:08:30.032 24721 25302 Info FA App measurement initialized, version: 43008
2021/09/20 20:08:30.032 24721 25302 Info FA To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2021/09/20 20:08:30.033 24721 25302 Info FA To enable faster debug mode event logging run:
2021/09/20 20:08:30.033 24721 25302 Info FA   adb shell setprop debug.firebase.analytics.app com.evenlycoolergames.biomesqa
2021/09/20 20:08:30.046 24721 25302 Error FA Missing google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI
2021/09/20 20:08:30.048 24721 25237 Warn FA Cannot log screen view event when the app is in the background.
2021/09/20 20:08:30.049 24721 25302 Error FA Uploading is not possible. App measurement disabled

As you can see my Initializing Firebase log message happens first. Then the SetProductionEnvironment method is called which from the docs should set the default instance. However all calls to Analytics are generating the Missing google_app_id. Firebase Analytics disabled log.

I don't have any google-services.json file, because I want to do the configuration in code. I'd expect FirebaseApp.Create to set the default instance but that doesn't seem to be the case. What am I missing?

@chkuang-g
Copy link
Contributor

Hi @cado1982

FirebaseApp.Create() need to be called AFTER FirebaseApp.CheckAndFixDependenciesAsync() is complete.

Could you move SetProductionEnvironment to OnFirebaseAvailable()? For instance

    private void OnFirebaseAvailable()
    {
#if PRODUCTION
        SetProductionEnvironment();
#else
        SetDevelopmentEnvironment();
#endif
#if UNITY_IOS || UNITY_ANDROID
        FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
        SetupMessaging();
#endif
    }

@chkuang-g chkuang-g added needs-info Need information for the developer api: core labels Aug 27, 2022
@google-oss-bot google-oss-bot added the stale Don't have recent activity label Sep 2, 2022
@google-oss-bot
Copy link

Hey @cado1982. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link

Since there haven't been any recent updates here, I am going to close this issue.

@cado1982 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Oct 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: analytics api: core closed-by-bot needs-info Need information for the developer stale Don't have recent activity type: question
Projects
None yet
Development

No branches or pull requests

4 participants