Search Unity

Bug Firebase app creation failed

Discussion in 'Scripting' started by nimene505, May 18, 2023.

  1. nimene505

    nimene505

    Joined:
    Apr 12, 2023
    Posts:
    5
    hello everyone
    iam creating an android app using unity and i want to use firebase realtime database
    i used the package 10.7
    i got some error first about Firebase.Editor.dll it was an error related to IOs so i deleted the file since iam working on android app
    the previous error dispears but i still get this
    InitializationException: Firebase app creation failed.
    Firebase.FirebaseApp.CreateAndTrack (Firebase.FirebaseApp+CreateDelegate createDelegate, Firebase.FirebaseApp existingProxy) (at /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/linux_unity/app/swig/Firebase.App_fixed.cs:2450)
    Firebase.FirebaseApp.Create () (at /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/linux_unity/app/swig/Firebase.App_fixed.cs:1954)
    FirebaseManagerScript.Start () (at Assets/FirebaseManagerScript.cs:17)

    and this is my code
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using Firebase;
    4. using Firebase.Database;
    5. using UnityEngine;
    6.  
    7. public class FirebaseManagerScript : MonoBehaviour
    8. {
    9.     // Start is called before the first frame update
    10.     DatabaseReference databaseRef;
    11.  
    12.     void Start()
    13.     {
    14.         Debug.Log("Connecting..");
    15.         // Initialize Firebase
    16.         //Dont use FirebaseApp.DefaultInstance.SetEditorDatabaseUrl
    17.        Firebase.FirebaseApp.Create ();
    18.         databaseRef = FirebaseDatabase.DefaultInstance.RootReference;
    19.  
    20.         Debug.Log("Firebase Connected");
    21.  
    22.         // Attach listener to the desired variable
    23.        
    24.     }
    25. }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    How to troubleshoot build failures:

    First, make a blank project with a single blank scene and prove that it builds successfully.

    If the blank project does NOT build, go fix your Unity installation or your other tools, such as Android SDK, NDK, JDK, etc. It may even be necessary to change to a different version of Unity3D. It is generally best to stay with LTS versions of Unity3D.

    Until you can build a blank project to the target platform, don't fiddle with anything else.

    Once you can build a blank project, now bisect the problem by bringing over parts of your current project and building it one subsystem at a time, perhaps stubbing things out that might trigger compiler errors.

    Most often things that prevent building are third-party libraries such as Firebase.

    Once you identify the subsystem, go to the documentation for it and make sure you are doing it correctly.

    It may also be helpful to work through a tutorial or two for whatever subsystem is making the build fail.

    Android build not building:

    Recently (circa July 2022) there have been reports of Unity's installer failing to install the Android Tools.

    https://forum.unity.com/threads/cant-build-for-android.1306098/

    Here was how I brought up Unity2020.3.41 and the Android SDK 31 on October 30, 2022:

    https://forum.unity.com/threads/aab...y-2021-3-8-with-jdk-1-8.1322211/#post-8551193

    Android Gradle errors and other related stuff:

    https://forum.unity.com/threads/unity-gradle-bug-please-help.1368018/#post-8625789
     
  3. nimene505

    nimene505

    Joined:
    Apr 12, 2023
    Posts:
    5
    thank you for your response sir
    i would ask can i keep my project and open it in another editor or do i need to open a new project in the new editor so firebase can work
     
  4. nimene505

    nimene505

    Joined:
    Apr 12, 2023
    Posts:
    5
    if anyone would be here looking for a solution i solved this by changing the unity editor
     
  5. fcodebue

    fcodebue

    Joined:
    Oct 27, 2016
    Posts:
    3
    You mean changing unity version? (i'm on 2022.3.2 LTS so atm i have no way up since it's the last safe release
     
  6. Izuen

    Izuen

    Joined:
    Sep 11, 2021
    Posts:
    1
    i had the same error in the 2023.1.5f1 unity editor
     
  7. chin13577

    chin13577

    Joined:
    May 8, 2017
    Posts:
    17
    Hi Guys. I've fixed this issue.
    my solution is
    1. download lasted sdk Add Firebase to your Unity project | Firebase for Unity (google.com)
    2. unzip the downloaded file.
    3. install FirebaseInstallations.unitypackage
    4. install FirebaseAnalytics.unitypackage
    5. download
    google-services.json
    and
    GoogleService-Info.plist
    to
    Assets/StreamingAssets/


    6. call
    Code (CSharp):
    1.  
    2.         FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
    3.         {
    4.             app = Firebase.FirebaseApp.DefaultInstance;
    5.             FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
    6.         });
    on Start().

    if you have already done this. you can check by Debug events | Google Analytics for Firebase

    if the debug receives your analytic log that means it works.

    PS. I'm using unity 2021.3.25f1
     
    Powzone, grbulat and RavenRoth like this.
  8. joefspiro

    joefspiro

    Joined:
    Jan 6, 2022
    Posts:
    42
    Is there a reason your are calling `FirebaseApp.Create()` directly? As discussed in the documentation, unless you need to change its defaults, the app is already created automatically.

    The best way to initialize the app is discussed in the Unity Setup guide and in code looks similar to this:

    Code (CSharp):
    1. Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {});
    Setting up the database has a couple more steps which are explained in depth there.

    If you have any more specific questions regarding getting your project to run in editor, build or work on device consult the Build Debug Guide.
     
  9. BlackBoxGaming

    BlackBoxGaming

    Joined:
    Mar 25, 2020
    Posts:
    10

    Thanks bro you save my day.
     
  10. grbulat

    grbulat

    Joined:
    Jan 11, 2022
    Posts:
    2
    First of all, thank you chin13577, your answer was very helpful.
    In addition to what you said, I could say that for me the problem was in wrong location for
    google-services.json
    , which I placed in
    Assets
    folder, as Firebase guide said. But after reading your answer and moving that file to
    Assets/StreamingAssets/
    , it worked.
     
    harensarma, An_Sayed and yusufgunay like this.
  11. yusufgunay

    yusufgunay

    Joined:
    Aug 30, 2020
    Posts:
    1
    Just Great Detail you did catch. Awesome.
     
    An_Sayed likes this.