Firebase Android Build FirebaseApp Failed to Initialize

I have a mobile app created using Unity 3D and Firebase and have had it deployed on the App Store for a little over a year. I’ve recently tried to get the build onto Google Play but whenever I run the app in the Android Studio Emulator the app successfully starts but never gets past the loading screen. Additionally, the app was deployed on the Google Play Store but I was informed by bug testers that the same problem occurred. In my Debug log I can’t find any noticeable errors besides:

FirebaseApp: Default FirebaseApp failed to initialize because no default options were found.
This usually means that com.google.gms:google-services was not applied to your gradle project.

These are my libraries in External Dependency Manager:

([rootProject] + (rootProject.subprojects as List)).each { project ->
    project.repositories {
        def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
        maven {
            url "https://maven.google.com"
        }
        maven {
            url (unityProjectPath + "/Assets/Firebase/m2repository") // Assets/Firebase/Editor/AnalyticsDependencies.xml:18, Assets/Firebase/Editor/AppDependencies.xml:22, Assets/Firebase/Editor/AuthDependencies.xml:20, Assets/Firebase/Editor/CrashlyticsDependencies.xml:20, Assets/Firebase/Editor/FirestoreDependencies.xml:20, Assets/Firebase/Editor/FunctionsDependencies.xml:20, Assets/Firebase/Editor/InstallationsDependencies.xml:20, Assets/Firebase/Editor/MessagingDependencies.xml:24, Assets/Firebase/Editor/RemoteConfigDependencies.xml:20, Assets/Firebase/Editor/StorageDependencies.xml:20
        }
        mavenLocal()
        mavenCentral()
    }
}
dependencies {
    implementation 'com.google.android.gms:play-services-base:18.2.0' // Assets/Firebase/Editor/AppDependencies.xml:17
    implementation 'com.google.firebase:firebase-analytics:21.3.0' // Assets/Firebase/Editor/StorageDependencies.xml:15
    implementation 'com.google.firebase:firebase-analytics-unity:11.6.0' // Assets/Firebase/Editor/AnalyticsDependencies.xml:18
    implementation 'com.google.firebase:firebase-app-unity:11.6.0' // Assets/Firebase/Editor/AppDependencies.xml:22
    implementation 'com.google.firebase:firebase-auth:22.1.2' // Assets/Firebase/Editor/AuthDependencies.xml:13
    implementation 'com.google.firebase:firebase-auth-unity:11.6.0' // Assets/Firebase/Editor/AuthDependencies.xml:20
    implementation 'com.google.firebase:firebase-common:20.3.3' // Assets/Firebase/Editor/AppDependencies.xml:13
    implementation 'com.google.firebase:firebase-config:21.4.1' // Assets/Firebase/Editor/RemoteConfigDependencies.xml:13
    implementation 'com.google.firebase:firebase-config-unity:11.6.0' // Assets/Firebase/Editor/RemoteConfigDependencies.xml:20
    implementation 'com.google.firebase:firebase-crashlytics-ndk:18.4.3' // Assets/Firebase/Editor/CrashlyticsDependencies.xml:13
    implementation 'com.google.firebase:firebase-crashlytics-unity:11.6.0' // Assets/Firebase/Editor/CrashlyticsDependencies.xml:20
    implementation 'com.google.firebase:firebase-firestore:24.8.1' // Assets/Firebase/Editor/FirestoreDependencies.xml:13
    implementation 'com.google.firebase:firebase-firestore-unity:11.6.0' // Assets/Firebase/Editor/FirestoreDependencies.xml:20
    implementation 'com.google.firebase:firebase-functions:20.3.1' // Assets/Firebase/Editor/FunctionsDependencies.xml:13     
    implementation 'com.google.firebase:firebase-functions-unity:11.6.0' // Assets/Firebase/Editor/FunctionsDependencies.xml:20
    implementation 'com.google.firebase:firebase-iid:21.1.0' // Assets/Firebase/Editor/MessagingDependencies.xml:17
    implementation 'com.google.firebase:firebase-installations:17.1.4' // Assets/Firebase/Editor/InstallationsDependencies.xml:13
    implementation 'com.google.firebase:firebase-installations-unity:11.6.0' // Assets/Firebase/Editor/InstallationsDependencies.xml:20
    implementation 'com.google.firebase:firebase-messaging:23.2.1' // Assets/Firebase/Editor/MessagingDependencies.xml:13
    implementation 'com.google.firebase:firebase-messaging-unity:11.6.0' // Assets/Firebase/Editor/MessagingDependencies.xml:24
    implementation 'com.google.firebase:firebase-storage:20.2.1' // Assets/Firebase/Editor/StorageDependencies.xml:13
    implementation 'com.google.firebase:firebase-storage-unity:11.6.0' // Assets/Firebase/Editor/StorageDependencies.xml:20
    implementation 'com.google.flatbuffers:flatbuffers-java:1.12.0' // Assets/Firebase/Editor/MessagingDependencies.xml:19
}
android {
  packagingOptions {
      exclude ('/lib/armeabi/*' + '*')
      exclude ('/lib/mips/*' + '*')
      exclude ('/lib/mips64/*' + '*')
      exclude ('/lib/x86/*' + '*')
      exclude ('/lib/x86_64/*' + '*')
  }
}

This is my code to initialize Firebase, which currently works on iOS devices:

public async void Start()
{
    var dependencyStatus = await FirebaseApp.CheckDependenciesAsync();
    if (dependencyStatus == DependencyStatus.Available)
    {
        FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
        app = Firebase.FirebaseApp.DefaultInstance;
        SceneManager.LoadSceneAsync("RegisterLogin");
    }
    else
    {
        SceneManager.LoadSceneAsync("LoadingFailed");
    }
}

The app successfully loads on both iOS platforms and in the editor. I’ve since deleted all Firebase SDK files from the project and reinstalled, including installing different versions of Firebase SDK to see if this might be the issue. I’ve also tried with different versions of Unity, including LTS support. I’ve also recreated an empty project and reimported Firebase and relevant scripts and this has not helped either. I’ve read that the issue can be resolved by adding dependencies to my build.gradle file, but from what I’ve read Unity manages this file itself unless you select to manage the file in Project Settings. Also, Firebase SDK says that it will handle any dependencies itself through the google.services file.

Both my google.services config files for Android and iOS are in my Assets folder. One small note is that the bundle identifier for my iOS app is different from my Android Package name. The bundle identifier matches what I set it as in my Firebase iOS App, and my Android Package Name matches what I set it as for my Firebase Android App.

I’m using Firebase packages:

  • Firebase Firestore
  • Firebase Messaging
  • Firebase Auth
  • Firebase Storage

I feel like I’ve tried everything I can and I’m at a complete loss for what might be causing this issue for Android specifically. Any help would be very appreciated!

recently resolved an issue similar to yours and thought I’d share the solution. Here’s what worked for me:

  1. Rename google-services.json to google-services-desktop.json.
  2. Create a folder structure inside the Plugins > Android directory:
  • FirebaseApp.androidlib
    • Inside FirebaseApp.androidlib, create two files and one folder:
      • AndroidManifest.xml
      • project.properties
      • res
        • Inside res, create another folder named values.
          • Inside values, create a file named google-services.xml.

Here’s the detailed content you need for each file:

project.properties

target=android-9
android.library=true

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.google.firebase.app.unity"
          android:versionCode="1"
          android:versionName="1.0">
</manifest>

google-services.xml
This file should contain the information from your google-services.json, but converted to XML. Here’s an example format you can use:

<?xml version='1.0' encoding='utf-8'?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:keep="@string/gcm_defaultSenderId,@string/google_storage_bucket,@string/project_id,@string/google_api_key,@string/google_crash_reporting_api_key,@string/google_app_id">
  <string name="gcm_defaultSenderId" translatable="false">YOUR_PROJECT_NUMBER</string>
  <string name="google_storage_bucket" translatable="false">YOUR_STORAGE_BUCKET</string>
  <string name="project_id" translatable="false">YOUR_PROJECT_ID</string>
  <string name="google_api_key" translatable="false">YOUR_API_KEY</string>
  <string name="google_crash_reporting_api_key" translatable="false">YOUR_API_KEY</string>
  <string name="google_app_id" translatable="false">YOUR_APP_ID</string>
</resources>

If you need help converting your google-services.json to google-services.xml, you can ask GPT for assistance or use the example above and replace the placeholder values with your project’s information.

Feel free to reach out if you need more detailed instructions!