Furebase on Linux

Hi everyone. I wanted to publish this as i have been working on the implementation of Firebase for Linux for a bout 3 weeks now and even if no one needs this i wanted to post it for myself just to have reference in case i ever forget what i did :slight_smile:

The explanation i am writing was tested on Unreal Engine 5.5.4 and Ubuntu 22.04. I built the whole thing on Windows 11 and only used Linux to test the project

General Summary
Just so you don’t go reading through the entire post, implementing Firebase on Linux is possible but with the help from different packages and some code editing. At the end, the ONLY function i used from Firebase was the Auth feature which provides me with the authorization token so i can use REST to query the RealTime Database. The Authorization also can create and Remove new users as it normally would in the plugin. The Login method i used for my project was the E-mail authentication provided by the plugin.

Windows, iOS & Android
I am using the plugin “Firebase Goodies” which was made by the nice people from Nineva to implement Firebase for those platforms. They were kind enough to help out when i needed it and in general i am very happy with all their products for Unreal not just Firebase related. If you need a good implementation for the most important bits of your project i highly recommend their products.

The plugin does not have support for Linux but i managed to bypass that issue by simply using the same setup that was available for Windows & MAC and just edited the code to include the new Linux entries. So look at how it works on Windows and just add new entries to use Linux as well.

The Plugin
My Build.cs file at the end looked like this (Note the Linux Entries, the rest of the build file is the same:

	void HandleLinux(ReadOnlyTargetRules Target)
	{
		LoadThirdPartyLibrary("libfirebase_app", Target);
		LoadThirdPartyLibrary("libfirebase_analytics", Target);
		LoadThirdPartyLibrary("libfirebase_auth", Target);
		LoadThirdPartyLibrary("libfirebase_database", Target);
		LoadThirdPartyLibrary("libfirebase_functions", Target);
		//LoadThirdPartyLibrary("libfirebase_firestore", Target);
		LoadThirdPartyLibrary("libfirebase_installations", Target);
		LoadThirdPartyLibrary("libfirebase_messaging", Target);
		LoadThirdPartyLibrary("libfirebase_remote_config", Target);
		LoadThirdPartyLibrary("libfirebase_storage", Target);
		
		LoadThirdPartyLibrary("libsnappy", Target);
		LoadThirdPartyLibrary("libleveldb", Target);
		LoadThirdPartyLibrary("libflatbuffers", Target);
		LoadThirdPartyLibrary("liblibuWS", Target);
		LoadThirdPartyLibrary("libfirebase_rest_lib", Target);
		
	}

		
		if (Target.Platform == UnrealTargetPlatform.Linux)
		{
			StaticLibExtension = ".a";
		}	

		if (Target.Platform == UnrealTargetPlatform.Linux)
		{
		
			PublicDefinitions.Add("FG_ENABLE_EDITOR_SUPPORT=1");
			
// Construct the sysroot path for your toolchain
string SysrootPath = @"C:\UnrealToolchains\v23_clang-18.1.0-rockylinux8\x86_64-unknown-linux-gnu";
			PublicSystemLibraryPaths.Add(Path.Combine(SysrootPath, "usr", "lib"));
			

		
			PublicAdditionalLibraries.Add("pthread");
			PublicAdditionalLibraries.Add("stdc++");
			
			// Add missing system libs needed by Firebase on Linux
			PublicAdditionalLibraries.Add("secret-1");
			PublicAdditionalLibraries.Add("glib-2.0");
			PublicAdditionalLibraries.Add("mvec");
			PublicAdditionalLibraries.Add("m");
			
			PublicAdditionalLibraries.Add("gobject-2.0");
			PublicAdditionalLibraries.Add("gio-2.0");
			
			PublicAdditionalLibraries.Add("curl");
			PublicAdditionalLibraries.Add("dl");


		}
	}
}

As a general note, in the plugin you shall find many entries which will have this in their code:
PLATFORM_WINDOWS || PLATFORM_MAC
You will need to add Linux to this so the plugin works on Linux.
PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX

Additionally as a tip note that since i am not using the Linux Editor for Unreal and am working on my projects in Windows, The Options Firebase needs to work are not taken by the plugin from the Project Editor. So you will need to add them manually to your plugin code ln the file: FirebaseSubsystem.cpp

Linux
By default Firebase is not officially supported on Linux and there is a reason they say it. I will try to summarize the steps i took to implement some of the features but i must warn you that without some code knowledge it will be hard to do in genera so please keep your questions to a minimum as even i don’t remember by heart all the steps i took and generally just followed the path of all the errors and tried to fix them as i went.

As a basic summary, although i did manage to build all of the libraries for Firebase on Linux like Auth, Database, Firestore, Messaging and others which are supported by the Firebase Goodies plugin, by design, only Auth will work on Linux without editing its core SDK. In general this although will not give you full control of Firebase from the plugin, will provide the necessary Token to access the RealTime Database.

Steps
1 - WSL
Wsl is a nice way to get a Linux terminal and a Linux build tool-set on Windows as it is already installed on Windows 11. I used it to initialize Ubuntu 22.04 which was the recommended at the time.

2 - SDK
Within WSL Linux environment You will need to download the exact same SDK for Firebase as the one used in the plugin so the same implementations will apply to Linux. You will also need to download the Unreal Engine Sources to get the Linux version of the Build Tools for Unreal

Important!: You MUST use the same Unreal Engine Build Tools on Linux as the ones used to build your project or you will have linker issues with the Firebase Libraries when building your final project in the editor.

For Unreal Engine you will need to run the Setup.sh and Create ProjectFiles.sh scripts which are provided in it to generate the necessary files for the build.

3 - Building
As a general guide my cmake command and build command looked like the one below but you must take into consideration that your paths may vary. You would run this in the Firebase SDK folder you downloaded. Note the directories which point to your Unreal Engine Build Tools.

cmake -B build_linux \
  -DCMAKE_C_COMPILER=/home/<username>/UnrealEngine_5_6/5.6-release/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v25_clang-18.1.0-rockylinux8/x86_64-unknown-linux-gnu/bin/clang \
  -DCMAKE_CXX_COMPILER=/home/<username>/UnrealEngine_5_6/5.6-release/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v25_clang-18.1.0-rockylinux8/x86_64-unknown-linux-gnu/bin/clang++ \
  -DCMAKE_SYSROOT=/home/<username>/UnrealEngine_5_6/5.6-release/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v25_clang-18.1.0-rockylinux8/x86_64-unknown-linux-gnu \
  -DCMAKE_C_FLAGS="--sysroot=/home/<username>/UnrealEngine_5_6/5.6-release/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v25_clang-18.1.0-rockylinux8/x86_64-unknown-linux-gnu -stdlib=libc++ -Wno-error=unknown-warning-option" \
  -DCMAKE_CXX_FLAGS="--sysroot=/home/<username>/UnrealEngine_5_6/5.6-release/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v25_clang-18.1.0-rockylinux8/x86_64-unknown-linux-gnu -stdlib=libc++ -Wno-shift-overflow -Wno-uninitialized -Wno-error=unknown-warning-option -Wno-error=deprecated-builtins -Wno-deprecated-builtins -Wno-error=macro-redefined -include cstdint" \
  -DCMAKE_EXE_LINKER_FLAGS="--sysroot=/home/<username>/UnrealEngine_5_6/5.6-release/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v25_clang-18.1.0-rockylinux8/x86_64-unknown-linux-gnu -stdlib=libc++" \
  -DFIREBASE_INCLUDE_ANALYTICS=ON \
  -DFIREBASE_INCLUDE_APP_CHECK=OFF \
  -DFIREBASE_INCLUDE_APP=ON \
  -DFIREBASE_INCLUDE_AUTH=ON \
  -DFIREBASE_INCLUDE_DATABASE=ON \
  -DFIREBASE_INCLUDE_DYNAMIC_LINKS=OFF \
  -DFIREBASE_INCLUDE_FIRESTORE=ON \
  -DFIREBASE_INCLUDE_FUNCTIONS=ON \
  -DFIREBASE_INCLUDE_GMA=OFF \
  -DFIREBASE_INCLUDE_INSTALLATIONS=ON \
  -DFIREBASE_INCLUDE_MESSAGING=ON \
  -DFIREBASE_INCLUDE_REMOTE_CONFIG=ON \
  -DFIREBASE_INCLUDE_STORAGE=ON \
  -DFIREBASE_DOWNLOAD_DEPENDENCIES=ON \
  -DBUILD_TESTING=OFF

To finally generate the *.a" Libraries you would run:

cmake --build build_linux --target firebase_app firebase_auth firebase_database firebase_firestore firebase_remote_config firebase_analytics firebase_messaging firebase_functions firebase_installations firebase_storage -j$(nproc)

In general i managed to build all of the libraries for Firebase, excluding Firestore (although it builds it needs some extra steps to work) which i didn’t need anyways.

Conclusion & Catch
Firebase libraries will all build at the end for Linux and i was able to get to the point of them actually loading within the project… However…

Firebase officially supports C++ on Windows, macOS, iOS, Android — but not Linux.
On Linux builds:

firebase::App initializes fine.
DatabaseReference::GetValue() (and others) compile and return a Future.

But the event loop that resolves Futures never runs, because the Linux backend isn’t implemented.

So you see Calling query.GetValue()…, and then nothing — exactly what i am observing.

That’s why:
On Windows/iOS/Android → the platform-specific Firebase SDK pumps the networking & futures.
On Linux → it’s a stub, so the Future never completes.

Meaning…
Firebase functions like Database Listeners, Database entries and other features will fire a request, but on Linux there needs to be a loop which cycles through them, which was removed by the creators long ago. So the features will look like they are working, there will be no errors but the functions will never return anything.

The Auth functionality which works on Linux uses the route of Request - > Reply so there is no Asynchronous waiting and returns. Any other function however does not work like that.

Bottom Line
As i mentioned earlier, i used the Auth functionality from the plugin on Linux to get the Authorization Token once a user logs in and then i simply use REST queries on Firebase Database to get or set anything i need.

I mainly needed just the Authorization and Database to work on my project. The rest of the functionality and features Firebase provides (at least for Linux) were not so important to me. If this is what you need and are willing to spend the time to chase build errors while fixing them, then you could try this route.

Thank You
I hope this saves you some time when researching this topic as i couldn’t find much information on the subject. As i mentioned before, please don’t attempt this if you cannot find your own way as i honestly wouldn’t even remember what i did. Most of the issues you might encounter are pretty straight forward and with some ChatGPT as well as some stubbornness can be resolved :slight_smile: