Tech Journal - Firebase and Unity, Remote Config keep fetching wrong data

Thumbnail 1

Admit it, Unity is too bloated. The software/engine had envolved into a monstrous being with gross tentacles and ugly mouth, not very different from a Lovecraftian being. Google is facing the same problem. And when the two merged together we have something worse than Cronenberg demon-lord. By that don’t forget to mention the whole mess, love-hat relationship between Unity and Gradle as well, when sometime one of the two caused crazy build-related issues that just so unintelligible. This is, first and foremost, the disadvantage when developer use too many complex, abstract level software and wrapper. Secondly, this gives us more motivation to ditch both Google (yup! we ditched Google Drive and host our own Cloud instead!) and go further away from Unity as well.

This tech journal will talk about a bug we met recently. The issue was weird, chaotic but as always, super easy to fix once you get the key points. But first, let’s me summarize the problem.

A. The Problem

  • Unity Engine version: 2020.3.48f1
  • Firebase App Unity Version: 9.6.0
  • Let’s say we have a running Android Game created in Unity called: Project A.
  • Project A is linked with Firebase service FirebaseServiceA from the google-services.json file.
  • In FirebaseA there are Remote Configs provided. From client of Project A we can fetch/request these configs normally.
  • Due to management and changes in operation. Project A cloned to Project B (the codebase is mostly the same), and the Firebase provider to a new service instance, let name it FirebaseServiceB
  • Unfortunately, from client of Project B, fetched values come from FirebaseServiceA instead.
  • Interestingly, in UnityEditor (of Project B), the RemoteConfig works extremely normal.

Why it happens?

B. Attemps

Recheck the google-services.json
  • Obviously, that is the first solution comes to my mind.
  • Double check twice but nothing wrong.
Re-allocated the google-services.json to StreamingAssets
  • While tweaking the google-services.json, we accidently deleted the file.
  • Funnily, the app (on Unity Editor) run and behave normally as well.
  • It turns out that there is a third file google-services-desktop in StreamingAssets. The name suggests that when running from Unity Editor the engine and Firebase Unity will pick this file up.
  • So, we re-allocate the file as well but nothing changed.
Delete GoogleService-Info.plist
  • Although this file is only used in IOS Build, we put it into the project folder as well.
  • Our educated guess is that although this file is not used, the engine still “scrape” metadata from this and points to FirebaseServiceA instead.
  • After deleting the file and build, nothing changed.

Other solutions:

We expect that the app may still cache old settings in somewhere. So we:

  • Purge & Regenerate the Library/ folder
  • Android -> Force Resolve numerous time.

Still, nothing changed!

C. Solution

  • It turns out that our assumption was correct, there was one setting that had been cached, this was the file google-services.xml in \Assets\Plugins\Android\Firebase\res\values

  • The file was supposed to auto-regen if google-services.json changes, but no it didn’t!

  • It appears that there were serveral issues related to this file and people all wondered about why this file not generatd automatically!

E.g: https://github.com/firebase/quickstart-unity/issues/880

  • In our scenario, we relied on AntonPetrov83' Answer and created a script like this
    static public void RegenerateFile()
    {
        AssetDatabase.Refresh();
        GenerateXmlFromGoogleServicesJson.ForceJsonUpdate(false);
    }

  • Run this script, the output may not be in your wanted folder location. Still, you can easily paste the new generated file into \Assets\Plugins\Android\Firebase\res\values as you may want.

Tech Journal Ends Here