skip to Main Content

I am building an app using unity2022.3.11.
The error
"The type initializer for ‘Firebase.FirebaseApp’ threw an exception"
is occurring in this code when launching on an Android device after build.

await FirebaseApp.CheckAndFixDependenciesAsync();
  1. What is the cause of this error?
  2. Is this due to build or is there something I should add from firebase unitypackage?
  3. If it cause of build, how do I configure gradle?

Resolve was done with the Android resolver in the External dependency manager.

Placed them in Assets/Plugins/Android.

baseProjectTemplate.gradle
gradleTemplate.properties
mainTemplate.gradle
settingTemplate.gradle

Filled in gradleTemplate.properties.

android.useAndroidX=true
android.enableJetifier=true

2

Answers


  1. As I understand this, this functions should not be awaited as shown below
    (This is an example of a FirebaseInit script I wrote)

    void Start()
    {
        FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
        {
    
            var dependencyStatus = task.Result;
            if (dependencyStatus == DependencyStatus.Available)
            {
                FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
                FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventLogin);
                Debug.Log("The Firebase Is INIT and is tracking");
    
                FetchDataAsync();
            }
            else
            {
                Debug.LogError(string.Format(
                  "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
            }
    

    I hope this will help you with resolving your error

    Login or Signup to reply.
  2. As mentioned by TheCoderEll, typically you should not await CheckAndFixDependenciesAsync.

    The easiest/ most straightforward way is to use ContinueWithOnMainThread as shown in Firebase’s Level up With Firebase:

    
    using Firebase.Extensions;
    
    //...
    
        private void InitializeFirebaseAndStartGame()
        {
          Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(
            previousTask => 
            {
              var dependencyStatus = previousTask.Result;
              if (dependencyStatus == Firebase.DependencyStatus.Available) {
                // Create and hold a reference to your FirebaseApp,
                app = Firebase.FirebaseApp.DefaultInstance;
                // Begin/perform all downstream/Firebase dependent functionality from here
              } else {
                UnityEngine.Debug.LogError(
                  $"Could not resolve all Firebase dependencies: {dependencyStatus}n" +
                  "Firebase Unity SDK is not safe to use here");
              }
            });
        }
    

    As for your build errors consult the following: Debugging the Game Build, Install and Run Process and EDM4U Usage Troubleshooting Guide

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search