Unity Firebase Initialization Exception

I have a problem with Firebase in my Unity project. Firebase SDK was imported into the project, built, no errors during this process.

The SHA-1 key was generated using keytool and added to the Firebase project in the console.

google-services.json has also been added to the Assets folder.

A simple script to initialize Firebase:

DependencyStatus dependencyStatus = DependencyStatus.UnavailableOther;
// Use this for initialization
void Start () 
{
    Debug.Log ("Start FireBase");
    dependencyStatus = FirebaseApp.CheckDependencies();

    if (dependencyStatus != DependencyStatus.Available) 
    {
        FirebaseApp.FixDependenciesAsync().ContinueWith(task => 
        {
            dependencyStatus = FirebaseApp.CheckDependencies();
            if (dependencyStatus == DependencyStatus.Available) 
            {
                InitializeFirebase();
            } 
            else 
            {
                Debug.LogError("Could not resolve all Firebase dependencies: " + dependencyStatus);
            }
        });
    } 
    else 
    {
        InitializeFirebase();
    }
}

void InitializeFirebase() 
{
    FirebaseAnalytic.Instance().setAnalyticsCollectionEnabled(true);
    FirebaseAnalytic.Instance().setUserProperty(FirebaseAnalytics.UserPropertySignUpMethod, "Google");
    FirebaseAnalytic.Instance().setUserId(SystemInfo.deviceUniqueIdentifier);
    FirebaseAnalytic.Instance().logEvent("LogIn", FirebaseAnalytics.EventLogin);
    Debug.Log ("FirebaseAnalytics Logined");
}

Thus, the application creates and runs without crashing. But through adb logcat -s UnityI see the following:

I/Unity   (27030): Start FireBase

I/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)
I/Unity   (27030):

I/Unity   (27030): Firebase App initializing app com.boldstatementproductions.mcpro (default 1).

I/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)
I/Unity   (27030):

W/Unity   (27030): Callback module already shut down

W/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

E/Unity   (27030): java_app

E/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

I/Unity   (27030): Firebase App initializing app com.boldstatementproductions.mcpro (default 1).

I/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

W/Unity   (27030): Callback module already shut down

W/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

E/Unity   (27030): java_app

E/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

I/Unity   (27030): InitializationException: Failed to initialize the default Firebase App.

I/Unity   (27030):   at Firebase.FirebaseApp.CreateAndTrack (Firebase.CreateDelegate createDelegate) [0x00000] in <filename unknown>:0

I/Unity   (27030):   at Firebase.FirebaseApp.Create () [0x00000] in <filename unknown>:0

I/Unity   (27030):   at Firebase.FirebaseApp.get_DefaultInstance () [0x00000] in <filename unknown>:0

I/Unity   (27030):   at Firebase.Analytics.FirebaseAnalytics..cctor () [0x00000] in <filename unknown>:0

I/Unity   (27030): Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Firebase.Analytics.FirebaseAnalytics

I/Unity   (27030):   at FirebaseDependencyResolver.InitializeFirebase () [0x00000] in <filename unknown>:0

I/Unity   (27030):   at FirebaseDependencyResolver.Start () [0x00000] in <filename unknown>:0

I/Unity   (27030): (Filename:  Line: -1)

Including any of these messages did not help. What am I missing? I followed the installation of Firebase for Unity step by step. This mistake has been scaring me for a week already!

+8
source share
4

, 1245321653214- reimport Firebase , Admob , Firebase.

Firebase, Admob, Firebase, Admob. Admob Firebase, , "play-services-blah-blah.aar".

- : , , , , (10 ), , .. , , .

, .

, VEEERY , .

Be VEEERY careful with files similar to those

, , .

+5

, , ( Firebase Remote), , Firebase Analytics, Remote Config , , , .

:

DependencyStatus dependencyStatus = FirebaseApp.CheckDependencies();
    if (dependencyStatus == DependencyStatus.Available)
        InitializeFirebase();
    else Debug.LogError("Remote Config Could not resolve all Firebase dependencies: " + dependencyStatus);

...

0

- , Unity. , gradle (mainTemplate.gradle), /Android/Firebase/res/values.xml . Xml

: gradle, Firebase/res res - mainTemplate.gradle Android

    sourceSets {
        main {
                res.srcDirs += 'Firebase/res'
        }
}

:  1. google-services.xml  2. Temp/ Unity.  3. , Temp/Firebase values.xml  4. mainTemplate.gradle Firebaes/res

0

, .

Unity 2018.3,8f1 Firebase 5.4.4. Unity 2019.2.6f1, Firebase. , . , . , , , . ( firebase, , )

: FirebaseAuth, FirebaseMessaging, FirebaseRemoteConfig, FirebaseAnalytics.

FirebaseCrashlytics, .

0

Source: https://habr.com/ru/post/1016855/


All Articles