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


  1. If you haven't yet connected your app to your Firebase project, do so from the Firebase console.
  2. Add Firebase to your Android project.
  3. Add the dependency for Firebase Realtime Database to your app-level build.gradle file:

    dependencies {
         implementation ''
  4. Link the libapp.a and libdatabase.a static library, from the C++ SDK.


  1. If you haven't yet connected your app to your Firebase project, do so from the Firebase console.
  2. Add Firebase to your iOS project.
  3. Include the following Pod in your Podfile:

    pod 'Firebase/Database'
  4. Run pod install

  5. Add firebase.framework and firebase_database.framework, from the C++ SDK, to your Xcode 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.

Send feedback about...

Need help? Visit our support page.