title: Unity Firebase [to Android] error when using database and auth package in one project
body: <p>I'm developing an app for Android in Unity3d that uses Firebase Authentication, and it worked just fine until I tried to use the Firebase database package. It imported just fine. But when I typed code to set my database in the Start() function for my app such as <code>FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://YOUR-Firebase-APP.Firebaseio.com/");</code>  (wich is in the Firebase unity guide <a href="https://Firebase.google.com/docs/database/unity/start" rel="nofollow noreferrer">https://Firebase.google.com/docs/database/unity/start</a>). it crashes almost everytime I use authentication or database functions, or a few seconds after.</p>
  
  <p>This is my start() function before I added the database package:</p>
  
  <pre><code>Firebase.Auth.FirebaseAuth auth;
  Firebase.Auth.FirebaseUser user;
  Firebase.DependencyStatus dependencyStatus = Firebase.DependencyStatus.UnavailableOther;
  
      void Start () {
          dependencyStatus = Firebase.FirebaseApp.CheckDependencies();
          if (dependencyStatus != Firebase.DependencyStatus.Available) {
              Firebase.FirebaseApp.FixDependenciesAsync().ContinueWith(task =&gt; {
                  dependencyStatus = Firebase.FirebaseApp.CheckDependencies();
                  if (dependencyStatus == Firebase.DependencyStatus.Available) {
                      InitializeFirebase();
                  } else {
                      // This should never happen if we're only using Firebase Analytics.
                      // It does not rely on any external dependencies.
                      Debug.LogError(
                          "Could not resolve all Firebase dependencies: " + dependencyStatus);
                  }
              });
          } else {
              InitializeFirebase();
          }
  }void InitializeFirebase() {
          Debug.Log("Setting up Firebase Auth");
          auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
          auth.StateChanged += AuthStateChanged;
      }
      // Track state changes of the auth object.
      void AuthStateChanged(object sender, System.EventArgs eventArgs) {
          if (auth.CurrentUser != user) {
              if (user == null &amp;&amp; auth.CurrentUser != null) {
                  Debug.Log("Signed in " + auth.CurrentUser.DisplayName);
              } else if (user != null &amp;&amp; auth.CurrentUser == null) {
                  Debug.Log("Signed out " + user.DisplayName);
              }
              user = auth.CurrentUser;
              //Debug.Log("Signed in " + auth.CurrentUser.DisplayName);
  
          }
      }
  </code></pre>
  
  <p>And this is my code after I applied the database connection (I just added a variable at the beggining and few lines in the InitializeFirebase() Function):</p>
  
  <pre><code>Firebase.Auth.FirebaseAuth auth;
  Firebase.Auth.FirebaseUser user;
  DatabaseReference mRef;
  Firebase.DependencyStatus dependencyStatus = Firebase.DependencyStatus.UnavailableOther;
  
      void Start () {
  
  
          dependencyStatus = Firebase.FirebaseApp.CheckDependencies();
          if (dependencyStatus != Firebase.DependencyStatus.Available) {
              Firebase.FirebaseApp.FixDependenciesAsync().ContinueWith(task =&gt; {
                  dependencyStatus = Firebase.FirebaseApp.CheckDependencies();
                  if (dependencyStatus == Firebase.DependencyStatus.Available) {
                      InitializeFirebase();
                  } else {
                      // This should never happen if we're only using Firebase Analytics.
                      // It does not rely on any external dependencies.
                      Debug.LogError(
                          "Could not resolve all Firebase dependencies: " + dependencyStatus);
                  }
              });
          } else {
              InitializeFirebase();
          }
  void InitializeFirebase() {
          Debug.Log("Setting up Firebase Auth");
          auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
          auth.StateChanged += AuthStateChanged;
          FirebaseApp app = FirebaseApp.DefaultInstance;
          app.SetEditorDatabaseUrl("https://testapp-509c4.firebaseio.com/");
          mRef = FirebaseDatabase.DefaultInstance.RootReference;
      }
      // Track state changes of the auth object.
      void AuthStateChanged(object sender, System.EventArgs eventArgs) {
          if (auth.CurrentUser != user) {
              if (user == null &amp;&amp; auth.CurrentUser != null) {
                  Debug.Log("Signed in " + auth.CurrentUser.DisplayName);
              } else if (user != null &amp;&amp; auth.CurrentUser == null) {
                  Debug.Log("Signed out " + user.DisplayName);
              }
              user = auth.CurrentUser;
              //Debug.Log("Signed in " + auth.CurrentUser.DisplayName);
  
          }
      }
  </code></pre>
  
  <p>I'm not sure what the problem is. Maybe both instances try to access the same permission or instance. I get this error on the log everytime I try functions like <code>auth.CreateUserWithEmailAndPasswordAsync(email, password)</code> OR <code>italicauth.SignInWithEmailAndPasswordAsync(username_text,password_text)</code>
  wich worked fine before I try to connect to firebase database</p>
  
  <p>The Android logcat shows this everytime I do one of those functions (even if it crashes or not): </p>
  
  <pre><code>12-01 00:55:51.214 4615-4639/? I/Unity: NullReferenceException: Object reference not set to an instance of an object
      at Intro.Login () [0x00000] in &lt;filename unknown&gt;:0 
      at UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) [0x00000] in &lt;filename unknown&gt;:0 
      at UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) [0x00000] in &lt;filename unknown&gt;:0 
      at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) [0x00000] in &lt;filename unknown&gt;:0 
      at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in &lt;filename unknown&gt;:0 
      at UnityEngine.UI.Button.Press () [0x00000] in &lt;filename unknown&gt;:0 
      at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00000] in &lt;filename unknown&gt;:0 
      at UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in &lt;filename unknown&gt;:0 
      at UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngi
  12-01 00:55:51.224 21998-22429/? E/AsyncOperation: serviceID=16, operation=ValidateAuthServiceOperation
      java.lang.NullPointerException: onPostInitComplete can be called only once per call to getRemoteService
          at iri.a(:com.google.android.gms:74)
          at ioj.a(:com.google.android.gms:987)
          at ipf.a(:com.google.android.gms:66)
          at ixg.a(:com.google.android.gms:284)
          at eks.a(:com.google.android.gms:125)
          at eks.a(:com.google.android.gms:113)
          at ixn.run(:com.google.android.gms:113)
          at jaq.run(:com.google.android.gms:450)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
          at jew.run(:com.google.android.gms:17)
          at java.lang.Thread.run(Thread.java:841)
  </code></pre>
  
  <p>Please help, if you need more code from my project just let me know.
  Thank You</p>