Get Started with Firebase Realtime Database for C++

The Firebase Realtime Database stores and synchronizes data using a NoSQL cloud database. Data is synchronized across all clients in realtime, and remains available when your app goes offline.

Before you begin

Before you can use Firebase Realtime Database, you need to:

  • Register your C++ project and configure it to use Firebase.

    If your C++ project already uses Firebase, then it's already registered and configured for Firebase.

  • In your project-level build.gradle file, make sure to include Google's Maven repository in both your buildscript and allprojects sections.

  • Add the Firebase C++ SDK to your C++ project.

Note that adding Firebase to your C++ project involves tasks both in the Firebase console and in your open C++ project (for example, you download Firebase config files from the console, then move them into your C++ project).

Setting up public access

The Realtime Database provides a declarative rules language that allows you to define how your data should be structured, how it should be indexed, and when your data can be read from and written to. By default, read and write access to your database is restricted so only authenticated users can read or write data. To get started without setting up Authentication, you can configure your rules for public access. This does make your database open to anyone, even people not using your app, so be sure to restrict your database again when you set up authentication.

Create and initialize firebase::App

Before you can access the Realtime Database, you'll need to create and initialize the firebase::App.

Include the header file for firebase::App:

#include "firebase/app.h"


Create the firebase::App, passing the JNI environment and a jobject reference to the Java Activity as arguments:

app = ::firebase::App::Create(::firebase::AppOptions("APPLICATION NAME"), jni_env, activity);


Create the firebase::App:

app = ::firebase::App::Create(::firebase::AppOptions("APPLICATION NAME"));

Access the firebase::database::Database class

The firebase::database::Database is the entry point for the Firebase Realtime Database C++ SDK.

::firebase::database::Database *database = ::firebase::database::Database::GetInstance(app);

If you have chosen to use public access for your rules, you can proceed to the sections on saving and retrieving data.

Setting up restricted access.

If you do not want to use public access you can add Firebase Authentication to your app to control access to the database.

Next Steps

Known Issues

  • On desktop platforms (Windows, Mac, Linux), the Firebase C++ SDK uses REST to access your database. Because of this, you must declare the indexes you use with Query::OrderByChild() on desktop or your listeners will fail.
  • The desktop workflow version of Realtime Database does not support offline or persistence.