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

Use realtime database Emulator from Unity #1218

Open
DiscoverTravel opened this issue Jan 11, 2022 · 9 comments
Open

Use realtime database Emulator from Unity #1218

DiscoverTravel opened this issue Jan 11, 2022 · 9 comments

Comments

@DiscoverTravel
Copy link

[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:9500/?ns=myns");
                var snapshot = await db.GetReference("test").GetValueAsync();
                Debug.Log("The value: "   snapshot.Value);
            }
        });
@paulinon
Copy link
Contributor

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 paulinon added the needs-info Need information for the developer label Jan 12, 2022
@DiscoverTravel
Copy link
Author

DiscoverTravel commented Jan 12, 2022

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

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Jan 12, 2022
@paulinon
Copy link
Contributor

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 paulinon added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Jan 17, 2022
@DiscoverTravel
Copy link
Author

DiscoverTravel commented Jan 18, 2022

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:9500/?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));
            }
        });
    }

}

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Jan 18, 2022
@paulinon
Copy link
Contributor

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 paulinon added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Jan 18, 2022
@google-oss-bot google-oss-bot added the stale Don't have recent activity label Jan 25, 2022
@google-oss-bot
Copy link

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!

@DiscoverTravel
Copy link
Author

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

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed stale Don't have recent activity needs-info Need information for the developer labels Jan 25, 2022
@paulinon
Copy link
Contributor

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 paulinon removed type: question needs-attention Need Googler's attention labels Jan 26, 2022
@mrchantey
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants