quickstart-unity icon indicating copy to clipboard operation
quickstart-unity copied to clipboard

Use realtime database Emulator from Unity

Open DiscoverTravel opened this issue 3 years ago • 9 comments

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.3.25f1
  • Firebase Unity SDK version: 8.7.0
  • Source you installed the SDK: .unitypackage (.unitypackage or Unity Package Manager)
  • Problematic Firebase Component: Database (Auth, Database, etc.)
  • Other Firebase Components in use: Database, Auth, Config (Auth, Database, etc.)
  • Additional SDKs you are using: _____ (Facebook, AdMob, etc.)
  • Platform you are using the Unity editor on: Windows (Mac, Windows, or Linux)
  • Platform you are targeting: Emulator (desktop) (iOS, Android, and/or desktop)
  • Scripting Runtime: IL2CPP (Mono, and/or IL2CPP)

[REQUIRED] Please describe the issue here:

Unity crash if use local instance of Database (Emulator) In unity crash log: ERROR: Could not initialize persistence: Unable to find app data directory. Crash !!!

Steps to reproduce:

Use this code to connect to the emulator

Relevant Code:

FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(async task =>
        {
            var dependencyStatus = task.Result;
            if (dependencyStatus == DependencyStatus.Available)
            {
                FirebaseDatabase db = Firebase.Database.FirebaseDatabase.GetInstance("http://localhost:9000/?ns=myns");
                var snapshot = await db.GetReference("test").GetValueAsync();
                Debug.Log("The value: " + snapshot.Value);
            }
        });

DiscoverTravel avatar Jan 11 '22 19:01 DiscoverTravel

Hi @DiscoverTravel,

Could you provide the complete and detailed steps to replicate this behavior? I haven't encountered the issue using the information you provided so far.

paulinon avatar Jan 12 '22 16:01 paulinon

Hi @paulinon, Thanks for the reply.

The steps are simple:

  • I created a new unity 3D project on windows
  • I have set up the Android platform
  • I imported the realtime database package (sdk version 8.7.0)
  • I hooked the MonoBehavior class which contains the code indicated in an element of the project
  • I added the google-service.json file in the assets folder
  • I started the database emulator
  • I ran the indicated code

DiscoverTravel avatar Jan 12 '22 17:01 DiscoverTravel

Thanks for the additional information, @DiscoverTravel. Could you provide the full script containing the relevant code? I still haven't encountered the error message, and I think I may be missing something in my implementation.

paulinon avatar Jan 17 '22 15:01 paulinon

Hi @paulinon, this is the code. Remember to attach it as a script component to a GameObject of the project.

Best regards

using Firebase;
using Firebase.Database;
using Firebase.Extensions;
using UnityEngine;

public class FirebaseManager : MonoBehaviour
{

    void Start()
    {
        FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
        {

            var dependencyStatus = task.Result;
            if (dependencyStatus == DependencyStatus.Available)
            {

                Debug.Log("Firebase is ok");
                var app = FirebaseApp.DefaultInstance;

                FirebaseDatabase db = Firebase.Database.FirebaseDatabase.GetInstance("http://localhost:9000/?ns=myns");
                db.GetReference("test").GetValueAsync().ContinueWithOnMainThread(task =>
                   {
                       if (task.IsFaulted)
                       {
                           Debug.Log("Error");
                       }
                       else if (task.IsCompleted)
                       {
                           DataSnapshot snapshot = task.Result;
                           Debug.Log(snapshot.Value);
                       }
                   });
            }
            else
            {
                UnityEngine.Debug.LogError(System.String.Format("Could not resolve all Firebase dependencies: {0}", dependencyStatus));
            }
        });
    }

}

DiscoverTravel avatar Jan 18 '22 09:01 DiscoverTravel

Thanks for that, @DiscoverTravel. I wasn't able to replicate the issue using the steps you provided, but I did encounter the error message whenever Force Resolve returned an error.

Could you confirm if there are issues when going to Assets > External Dependency Manager > Android Resolver > Force Resolve? If there aren't any, could you replay the scene and see if the issue persists?

paulinon avatar Jan 18 '22 17:01 paulinon

Hey @DiscoverTravel. 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 avatar Jan 25 '22 02:01 google-oss-bot

Hello, for me the problem still exists. Force resolve succeeds. There are other threads on the web about this issue. I don't know what to add ... Windows 10

Greetings

DiscoverTravel avatar Jan 25 '22 09:01 DiscoverTravel

Hi @DiscoverTravel,

It's possible that you're facing a setup-related issue. Also, I got word from the team that this isn't officially supported yet as the Firebase Local Emulator Suite is currently in Beta. That being said, I'll mark this as a feature request for now.

You may refer to this thread for any updates.

paulinon avatar Jan 26 '22 17:01 paulinon

Plus 1 for this feature please! It would greatly reduce the friction in our automated testing workflow.

mrchantey avatar May 22 '22 05:05 mrchantey