google / mechahamster

Mecha Hamster is a game where you roll through customizable environments that you can share with your friends.
https://google.github.io/mechahamster/
Apache License 2.0
501 stars 199 forks source link

Unity integration with firebase realtime database works on unity editor but not on mobile devices. #24

Open praddyum opened 3 years ago

praddyum commented 3 years ago

I have been following the official firbase docs for integration of Unity v2020(LTS) and firebase realtime database (SDK v 7.1.0). It works completely fine in unity editor but not in any mobile devices.

Here is my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Firebase.Database;
using TMPro;

public class firebase_script : MonoBehaviour
{
    DatabaseReference reference;
    string text_place;
    public TextMeshProUGUI text;

    // Start is called before the first frame update
    void Start()
    {
        reference= FirebaseDatabase.DefaultInstance.RootReference;
    }
    public void get_updates(){
        reference.Child("plant").GetValueAsync().ContinueWith(task => {
            if(task.IsFaulted){
                Debug.Log("Failed to fetch Value");
            }
            else if(task.IsCompleted){
                DataSnapshot snapshot =task.Result;
                text_place=snapshot.Child("moisture").Value.ToString();

            }
        });
    }

    // Update is called once per frame
    void Update()
    {
        text.text=text_place;   
    }
}

and here is the logcat output

03-23 00:45:45.253  9618  9707 I Unity   : Company Name: <Striped>
03-23 00:45:45.253  9618  9707 I Unity   : Product Name: <Striped>
03-23 00:45:48.719  9618  9707 E Unity   : InitializationException:  Firebase app creation failed.
03-23 00:45:48.719  9618  9707 E Unity   :   at Firebase.FirebaseApp.CreateAndTrack (Firebase.FirebaseApp+CreateDelegate createDelegate, Firebase.FirebaseApp existingProxy) [0x000e3] in <efce830506c14731bd3b7a14d631487d>:0 
03-23 00:45:48.719  9618  9707 E Unity   :   at Firebase.FirebaseApp.Create () [0x00027] in <efce830506c14731bd3b7a14d631487d>:0 
03-23 00:45:48.719  9618  9707 E Unity   :   at Firebase.FirebaseApp.get_DefaultInstance () [0x00017] in <efce830506c14731bd3b7a14d631487d>:0 
03-23 00:45:48.719  9618  9707 E Unity   :   at Firebase.Database.FirebaseDatabase.get_DefaultInstance () [0x00000] in <265179cd3d324ba1be0c68f88dea310a>:0 
03-23 00:45:48.719  9618  9707 E Unity   :   at firebase_script.Start () [0x00000] in <a8ca21255e29484580e851c97ded26fa>:0 
03-23 00:45:48.719  9618  9707 E Unity   : 
03-23 00:45:48.739  9618  9707 E Unity   : InitializationException:  Firebase app creation failed.
03-23 00:45:48.739  9618  9707 E Unity   :   at Firebase.FirebaseApp.CreateAndTrack (Firebase.FirebaseApp+CreateDelegate createDelegate, Firebase.FirebaseApp existingProxy) [0x000e3] in <efce830506c14731bd3b7a14d631487d>:0 
03-23 00:45:48.739  9618  9707 E Unity   :   at Firebase.FirebaseApp.Create () [0x00027] in <efce830506c14731bd3b7a14d631487d>:0 
03-23 00:45:48.739  9618  9707 E Unity   :   at Firebase.FirebaseApp.get_DefaultInstance () [0x00017] in <efce830506c14731bd3b7a14d631487d>:0 
03-23 00:45:48.739  9618  9707 E Unity   :   at Firebase.Database.FirebaseDatabase.get_DefaultInstance () [0x00000] in <265179cd3d324ba1be0c68f88dea310a>:0 
03-23 00:45:48.739  9618  9707 E Unity   :   at button_script.Start () [0x00000] in <a8ca21255e29484580e851c97ded26fa>:0 
03-23 00:45:48.739  9618  9707 E Unity   : 
03-23 00:45:48.759  9618  9707 E Unity   : InitializationException:  Firebase app creation failed.
03-23 00:45:48.759  9618  9707 E Unity   :   at Firebase.FirebaseApp.CreateAndTrack (Firebase.FirebaseApp+CreateDelegate createDelegate, Firebase.FirebaseApp existingProxy) [0x000e3] in <efce830506c14731bd3b7a14d631487d>:0 
03-23 00:45:48.759  9618  9707 E Unity   :   at Firebase.FirebaseApp.Create () [0x00027] in <efce830506c14731bd3b7a14d631487d>:0 
03-23 00:45:48.759  9618  9707 E Unity   :   at Firebase.FirebaseApp.get_DefaultInstance () [0x00017] in <efce830506c14731bd3b7a14d631487d>:0 
03-23 00:45:48.759  9618  9707 E Unity   :   at Firebase.Database.FirebaseDatabase.get_DefaultInstance () [0x00000] in <265179cd3d324ba1be0c68f88dea310a>:0 
03-23 00:45:48.759  9618  9707 E Unity   :   at button_script.Start () [0x00000] in <a8ca21255e29484580e851c97ded26fa>:0 
03-23 00:45:48.759  9618  9707 E Unity   : 
03-23 00:45:48.830  9618  9707 E Unity   : Failed to read Firebase options from the app's resources. Either make sure google-services.json is included in your build or specify options explicitly.
03-23 00:45:48.830  9618  9707 E Unity   : 
03-23 00:45:48.830  9618  9707 E Unity   : Failed to read Firebase options from the app's resources. Either make sure google-services.json is included in your build or specify options explicitly.

I know it's showing firebase app creation failed but when i use it in unity editor it successfully pulll and push data to/from firebase but fails in mobile device.